1 Star 0 Fork 0

142vip/JavaScriptCollection

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
add.js 504 Bytes
一键复制 编辑 原始数据 按行查看 历史
/**
* 累加
*/
function add(...inputs) {
const args = Array.prototype.slice.call(inputs)
const _add = function () {
console.log('add', inputs)
args.push(...inputs)
// 返回函数
return _add
}
// 对参数数组做求和处理
_add.toString = function () {
// 设置sum的起始值为0
return args.reduce((sum, item) => {
console.log(sum, item)
return sum + item
})
}
// 返回函数
return _add
}
add(1, 6)(2)(3)
add(1)(2)(3)
add(1)(2, 3, 4)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/chufan443/JavaScriptCollection.git
git@gitee.com:chufan443/JavaScriptCollection.git
chufan443
JavaScriptCollection
JavaScriptCollection
main

搜索帮助