函数柯里化
本文最后更新于:2023年3月19日 晚上
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| function curry(fn) { return function curried(...args) { if (args.length >= fn.length) { return fn.apply(this, args); } else { return function (...args2) { return curryFn(...args, ...args2); }; } }; }
function sum(a, b, c) { return a + b + c; } const curriedSum = curry(sum); console.log(curriedSum(1, 2, 3)); console.log(curriedSum(1)(2, 3)); console.log(curriedSum(1)(2)(3));
|