javascript中的add(1)(2)(3)(4)是怎么实现的?实现如下:
var fn = function(a){
let sum = a;
let tempFn = function(b){
sum += b; //数据处理逻辑
return tempFn;
}
tempFn.getVal = function (){
return sum;
}
return tempFn;
} fn(1).getVal(); //
fn(1)(2)(3).getVal(); //
fn(1)(2)(3)(4)(5)(6)(7)...