简单参数

1
2
3
4
5
6
7
8
9
//函数定义
const f1 = (...p)=> console.log(...p)

//直接调用
f1(10, 20)

//call 和 apply 调用
f1.call(this, 10, 20)
f1.apply(this, [10, 20])

函数参数

1
2
3
4
5
const  f2 = (fun) => {
fun(10, 20);
}

f2(f1);

多个函数参数

1
2
3
4
5
6
7
8
const  f3 = (fun, afterFun) => {
fun(10, 20);
afterFun(10, 20);
}

f3(f1, function (...result){
console.log(...result)
});

混合参数

1
2
3
4
5
6
7
8
const f2 = (a, b, fun, afterFun) => {
fun(a, b);
afterFun(a, b);
}

f2(10, 20, f1, function (...result){
console.log(...result)
});

不定混合参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const  f2 = (fun, afterFun) => {
return function (){
console.log(...arguments)
fun.apply(this, arguments);

afterFun.apply(this, arguments);
}
}

f2(f1, function (...result){
console.log(...result)
}).call(this, 10, 20, 30, 40, 50);
// f2(f1, function (...result){
// console.log(...result)
// }).apply(this, [10, 20, 30, 40]);