实现 add()(1,2)(3,4)(7,8,9)()


function add(){
        var sum=0;
        function inner(pre,cur){
            return pre+cur;
        }
        sum=Array.prototype.slice.call(arguments).reduce(inner,sum);
        return function(){
            if(arguments.length==0){
                return sum;
            }else{
                sum=Array.prototype.slice.call(arguments).reduce(inner,sum);
                return arguments.callee;
            }
        }

    }
    console.log(add()(1)(2,3)());//6

---------------------

原文地址:https://www.cnblogs.com/shiyunfront/p/9709523.html