在JavaScript中解析rest参数的重点是什么?

时间:2018-02-12 17:50:30

标签: javascript ecmascript-6

JavaScript允许destructuring rest parameters



const add = (...[x, y, z]) => x + y + z;

console.log(add(1));          // NaN (y and z are undefined)
console.log(add(1, 2, 3));    // 6
console.log(add(1, 2, 3, 4)); // 6 (the fourth argument is not destructured)




然而,当你只是简单地写道时,我没有看到你为什么要这样做的原因:



const add = (x, y, z) => x + y + z;

console.log(add(1));          // NaN (y and z are undefined)
console.log(add(1, 2, 3));    // 6
console.log(add(1, 2, 3, 4)); // 6 (the fourth argument is ignored)




那么,在JavaScript中解析rest参数的重点是什么?

0 个答案:

没有答案