add(1)(2)(3)(4)

function add(x) {
    var sum = x;
    var tmp = function (y) {
        sum = sum + y;
        return tmp;
    };
    tmp.toString = function () {
        return sum;
    };
    return tmp;
}
console.log(add(1)(2)(3));  //6
console.log(add(1)(2)(3)(4));   //10
posted @ 2021-04-01 16:29  FE-神鸟  阅读(39)  评论(0编辑  收藏  举报