SOURCE

//函数科里化的要点就是,判断当前参数的长度
//如果长度小于函数所需参数的长度,则返回一个函数
//如果长度大于函数所需参数的长度,则直接执行
//函数参数的长度:fn.length


let curry = function(fn,...args){
    return args.length >=fn.length
    ? fn(...args)
    : (...newArgs)=>{return curry(fn,...args,...newArgs)}
}

function add1(x, y, z) {
    return x + y + z;
}
const add = curry(add1);
console.log(add(1, 2, 3));
console.log(add(1)(2)(3));
console.log(add(1, 2)(3));
console.log(add(1)(2, 3));


console 命令行工具 X clear

                    
>
console