Function.prototype.getValue = function () { let num = this.arr.reduce((x, y) => x + y) this.arr = [] return num } const foo = function (...args) { if (!Array.isArray(foo.arr)) { foo.arr = [] } foo.arr.push(...args) return foo } var f3 = foo(1)(2)(3)(4); console.log(f3.getValue()); // 10