function sum(){ var _args = Array.prototype.slice.call(arguments) console.log(_args) var add = function(){ _args.push(...arguments) return add } add.valueof = function(){ return _args.reduce((a,b)=>{ return a+b }) } return add}console.log(sum(1,2)(3).valueof())