SOURCE

function curry(fn, len=fn.length) {
    return _curry(fn, len);
}

function _curry(fn, len, ...args1) {
    return (...args2) => {
        const newArgs = [...args1, ...args2];
        if (newArgs.length < len) {
            return _curry(fn, len, ...newArgs);
        }
        return fn.call(null, ...newArgs);
    }
}

function add(a, b, c, d) {
    return a + b + c + d;
}

const currayAdd = curry(add);
console.log(currayAdd(1)(2, 3, 4))
console 命令行工具 X clear

                    
>
console