//函式柯里化封裝(這個封裝可以直接複製走使用) function curry(fn, args) { var length = fn.length; var args = args || []; return function () { newArgs = args.concat(Array.prototype.slice.call(arguments)); if (newArgs.length < length) { return curry.call(this, fn, newArgs); } else { return fn.apply(this, newArgs); } } } //需要被柯里化的函式 function multiFn(a, b, c) { return a * b * c; } //multi是柯里化之後的函式 var multi = curry(multiFn); console.log(multi(2)(3)(4)); console.log(multi(2, 3, 4)); console.log(multi(2)(3, 4)); console.log(multi(2, 3)(4));
https://juejin.cn/post/7111902909796712455