//
// curry = fn => {
// let arr = [];//
// judge = (...args)=>{
// if(!args[args.length-1]){
// return fn(arr);
// }else{
// arr.push(...args);
// return judge;//
// }
//
// };
// return judge;
// }
//
curry = fn => judge = (...args)=>{
return !args[args.length-1]?fn(args):(...arg)=>judge(...args,...arg);//judge
};
testCurry = (args)=>{
args.pop();//null
if(args.length<1){
return;
}
let sum = args.reduce((s,n)=>{
return s+n;
},0);
console.log("",args);
console.log("sum",sum);
return sum;
};
OnClick =()=>{
console.log(" OnClick");
let one = this.curry(this.testCurry)(1);
let two = one(2)(3)(4)(5);
let three = two(6,6,6,6);
three(null);
};
how does the second function understand how she saves the previously entered parameters?
Thank you for a detailed answer