# 编写一个函数,输出以下结果
预期结果:
const f1 = foo(1, 2, 3)
const f2 = foo(1)(2, 3)
const f3 = foo(1)(2)(3)(4)
const f4 = foo(1)(2)(3)(4)(5, 6)
console.log(f1.getValue()) // 6
console.log(f2.getValue()) // 6
console.log(f3.getValue()) // 10
console.log(f4.getValue()) // 21
编写foo函数如下:
function foo(...args) {
const target = (...arg1s) => foo(...[...args, ...arg1s])
target.getValue = () => args.reduce((p, n) => p + n, 0)
return target
}