SOURCE

function add() {
    // var args = [...arguments];
    var args = Array.prototype.slice.call(arguments)
    console.log(args)
    // 这里实现了一个递归,返回自己的函数,自己调用自己
    var fn = function () {
        args.push(...arguments);
        console.log(args)
        return fn
    };
    // 隐式转换
    fn.toString = function () {
        return args.reduce(function (a, b) {
            return a + b;
        });
    };

    // return (function () {
    //     console.log(args)
    //     return args.reduce(function (a, b) {
    //         return a + b;
    //     });
    // })()

    return fn
}


console.log(add(123))
console.log(add(1)(1, 2, 3)(2)(3)(45))

console 命令行工具 X clear

                    
>
console