function currying() {
const args = Array.prototype.slice.call(arguments);
const inner = function () {
args.push(...arguments);
return inner;
};
inner.__proto__[Symbol.toPrimitive] =
inner.toString =
inner.getValue =
() => args.reduce((prev, next) => prev + next, 0);
return inner;
}
const sum = currying(1)(2)(3);
console.log(sum*1);// 6
const res = currying(1, 2, 3, 4, 5)(6, 7)(8, 9)(10);
console.log(res.getValue()); // 55
console.log(res - 1); // 54
标签:面试题,const,log,res,args,add,inner,柯里化,currying
From: https://www.cnblogs.com/echoyya/p/17476313.html