参考文章: www.runoob.com/w3cnote/js-…
其中 apply ,在 ES6 中有更简洁的替代语法,...[]
...[1, 2, 3] // 1, 2, 3
讲数组的元素,分别拆出来,可当做参数传入
function add(x, y) {
return x + y
}
const numbers = [4, 38]
console.log(add(...numbers)) // 42 = 38 + 4
参考文章: www.runoob.com/w3cnote/js-…
其中 apply ,在 ES6 中有更简洁的替代语法,...[]
...[1, 2, 3] // 1, 2, 3
讲数组的元素,分别拆出来,可当做参数传入
function add(x, y) {
return x + y
}
const numbers = [4, 38]
console.log(add(...numbers)) // 42 = 38 + 4