function sum(...args) { function fn(...innerArgs){ args.push(...innerArgs); return fn; } fn.toString = function() { return args.reduce((total,curr)=> total + curr) } return fn; } console.log(sum(1,2,3)(4).toString())