函数柯里化

换一个版本的:

function curry() {
    const fn = arguments[0];
    let slice = Array.prototype.slice;
    let cache = slice.call(arguments)
    if (arguments.length - 1 < fn.length) {
        return function() {
            return curry.apply(null, cache.concat(slice.call(arguments)))
        }
    } else {
        return fn.apply(null, Array.prototype.slice.call(arguments, 1));
    }
}

function fun(name, age, high) {
    return name + '||' + age + '|' + high
}

var cb = curry(fun);
var b = cb('aaa')(12)(14);

console.log(b);
原文地址:https://www.cnblogs.com/jiajiaobj/p/13654849.html