提问人:j obe 提问时间:5/16/2023 最后编辑:j obe 更新时间:5/16/2023 访问量:53
对这个高级的咖喱函数感到困惑,它是如何工作的?
Confused by this advanced curried function, how is it working?
问:
我一直在学习咖喱函数,我理解了我读过的基本示例,但是我真的很想理解这个给出的高级函数示例,但我发现它令人困惑,如果有人可以帮助分解它,那就太好了,我理解接受一个函数,然后这个函数的参数被收集到一个数组中,但我不确定之后的逻辑或它是如何的加工。curry
...args
我还想知道价值是什么,它来自哪里?以及函数再次绑定到 args 的行发生了什么。(...args)
const curry = (fn) => {
return curried = (...args) => {
if (fn.length !== args.length) {
return curried.bind(null, ...args)
}
return fn(...args);
};
}
const totalNum = (x, y, z) => {
return x + y + z
}
const curriedTotal = curry(totalNum);
console.log(curriedTotal(10)(20)(30));
答: 暂无答案
评论
.length
fn.length !== args.length
curried
fn.length > args.length
!==
fn.length
fn
(a,b,c,d) => {}
totalNum.length == 3