SOURCE

const curry2 = function(fn, ...args){
    let restParam = [...args];
    return function(...args2){
        let restParam2 = [...args2]
        return fn(...[...restParam, ...restParam2])
    }
}

const curry3 = function(fn, ...args1){
    return function(...args2){
        return (function(arg){
            if(arg.length === fn.length){
                return fn(...arg)
            }else {
                return curry3(fn, ...arg)
            }
        })([...args1, ...args2])
    }
}

const curry = (fn, ...args1) => (...args2) => (
 arg => arg.length === fn.length ? fn(...arg) : curry(fn, ...arg)
)([...args1, ...args2]);

const foo = (a, b, c) => a * b * c;
console.log(curry3(foo)(2,3,4)); // -> 24
console.log(curry3(foo, 2)(3,4)); // -> 24
console.log(curry3(foo, 2, 3)(4)); // -> 24
console.log(curry3(foo, 2, 3, 4)()); // -> 24

function add(...args1){
    let restParam = [];
    restParam = [...args1]
    let adder = function(...args2){
        restParam.push(...args2)
        return adder
    }

    adder.toString = function(){
        return restParam.reduce((a,b)=>{
            return a+b;
        })
    }

    return adder
}


console.log(add(1,2,3))
console 命令行工具 X clear

                    
>
console