根据https://leetcode.com/problems/curry/editorial
以下2个实现是等价的:
var curry = function (fn) {
return function curried(...args) {
if (args.length >= fn.length) {
return fn.apply(this, args);
}
return curried.bind(this, ...args);
};
};
var curry = function (fn) {
return function curried(...args) {
if (args.length >= fn.length) {
return fn.apply(this, args);
}
return (...nextArgs) => curried.apply(this, args);
};
};
Q1:我无法理解
(...nextArgs) => curried.apply(this, args)
如何合并nextArgs
和args
。
我确实从
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind. 得到
Arguments to prepend to arguments provided to the bound function when invoking func
但是我无法从 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply (那里的附加示例看起来无关紧要)。
Q2:是否有官方来源描述
apply
的参数合并是如何发生的?
Q3:我如何使用 console.log 或类似
sum = (a,b,c) => a+b+c
的函数调查参数列表构建过程,以测试实现是否真的等效?