我知道必须非常小心地使用函数 Arguments object
但是对 Arguments 对象使用扩展语法是否有任何已知的缺点(优化/性能问题)?或者这完全没问题?
我想根据传递给函数的未知数量的参数创建一个数组:
function Numbers(){
this.numbers = [...arguments];
}
它看起来很整洁,在关于 Arguments 对象的 MDN 页面中甚至建议我可以为此使用扩展语法:
As you can do with any Array-like object, you can use ES2015's
Array.from()
method or spread syntax to convertarguments
to a real Array
但我还是想看看其他人对此有没有其他看法。
最佳答案
您还可以使用 rest parameters :
function Numbers(...numbers){
this.numbers = numbers;
}
关于javascript - 将扩展语法与函数 Arguments 对象一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39774101/