SOURCE

function Currying(func) {
    return new function() {
        var args = [].slice.call(arguments);

        // 使用闭包收集参数
        var _getter = function() {
            args = args.concat([].slice.call(arguments));
            return _getter;
        }

        _getter.toString = function() {
            return func.apply(null, args);
        }

        return _getter;
    }
}

/**
 * add(a, b, c, ...)
 */
function add() {
    return [].reduce.call(arguments, (a, b) => a + b);
}

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

                    
>
console