我有使用n
参数的回调函数。 n
是动态的。如何将n
参数从高阶函数动态传递给回调函数?
const callbackFn1 = (para1, para2, para3) =>{
//some code
}
const callbackFn2 = (para1, para2, para3, para4) =>{
//some code
}
const hoFn = (callback, ...rest){
return callback(rest[0], rest[1], rest[3],...,rest[n-1]) // how to pass like this?
}
hoFn(callbackFn1, para1, para2, para3)
hoFn(callbackFn2, para1, para2, para3, para4)
答案 0 :(得分:1)
function hoFn(callback, ...rest) {
callback(rest);
}
hoFn((params) => {
console.log(params);
}, "Lorem", "Ipsum", "lora")