实现add(2, 5); // 7 add(2)(5); // 7

  • Post author:
  • Post category:其他


 var add = function(x,r) {
        if(arguments.length == 1){
            return function(y) { return x + y; };
        }else{
            return x+r;
        }
    };
    console.log(add(2)(5));
    console.log(add(2,5));

控制台输出测试:

7,

7