封装实现:
//函数柯里化封装(这个封装可以直接复制走使用) 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 标签:multi,场景,console,log,args,讲解,return,科里,fn From: https://www.cnblogs.com/xiaoyaoweb/p/18149308