function sub_curry(fn) {
console.log(arguments)
console.log(fn)
let args = Array.prototype.slice.call(arguments, 1)
return function () {
let newArgs = args.concat(Array.prototype.slice.call(arguments))
return fn.apply(this, newArgs)
}
}
function curry(fn, length) {
// 获取需要柯里化函数的参数长度
length = length || fn.length;
var slice = Array.prototype.slice;
return function () {
if (arguments.length < length) {
let combined = [fn].concat(slice.call(arguments));
console.log("combined:", combined)
return curry(sub_curry.apply(this, combined), length - arguments.length);
} else {
return fn.apply(this, arguments)
}
}
}
在sub_curry中
console.log(arguments)和console.log(fn)为什么不同?
fn为何为一个函数不应该是下方的combined数组吗?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…