var add = function () {
var orig = 0;
var inner = function () {
for(var i = 0; i < arguments.length; i++) orig += arguments[i];
return inner
};
inner.valueOf = function () {return orig;};
return inner.apply(this, arguments);
};
console.log(add(2,1,1)(2)(5)+2)
console.log(add(5));
console.log(add(2,5))