function sum(x){ console.log('x:='+x); var y = function(x){ console.log('xx:='+x); console.log('y:='+y); return sum(x+y) } y.toString = y.valueOf = function(){ return x; } console.log('yy:='+y); return y; } sum(1)(2)(3)(4);//10
function sum(x){ console.log('x:='+x); var y = function(x){ console.log('xx:='+x); console.log('y:='+y); return sum(x+y) } y.toString = y.valueOf = function(){ return x; } console.log('yy:='+y); return y; } sum(1)(2)(3)(4);//10