实现如下这样的函数f(),要求调用深度不限
f(1).val === 1
f(1)(2).val === 3
f(1)(2)(3).val === 6
f(a0)(a1)(a2)…(an).val === a0+a1+a2+…+an
let fn = (...a) => {
let arr = a;
let add = function(...b) {
arr = [...arr, ...b]
sumVal(arr)
return add;
}
let sumVal = (arr) => {
add.val = arr.reduce((a, b) => {
return a + b;
})
}
sumVal(arr)
return add;
}
console.log(fn(10)(1)(2).val)