标签:call prot turn each OLE code 推荐 扩展 es5
ES5利用arguments
// ES5 function sum () { let num = 0 Array.prototype.forEach.call(arguments, function (v) { num += v * 1 }) return num } console.log(sum(1, 2, 3, 4, 5)) 15
ES6不推荐arguments,用扩展符
// ES6 let sum = (...arr) => { let num = 0 arr.forEach(v => { num += v * 1 }) return num } console.log(sum(1, 2, 3, 4, 5))
15
标签:call prot turn each OLE code 推荐 扩展 es5
原文地址:https://www.cnblogs.com/allenzhang-920/p/12748890.html