var sum = function(a){
var fnc = function(a){
fnc.value += a || 0;
return fnc;
};
fnc.value = a || 0;
fnc.toString = toString;
return fnc;
},
toString = function(){
return this.value
};
alert(sum()); // ==> 0
alert(sum(2)); // ==> 2
alert(sum(1)(2)(3)); // ==> 6
alert(sum(4)(8)); // ==> 12
// и т.д.