frontend-interview icon indicating copy to clipboard operation
frontend-interview copied to clipboard

函数的arguments为什么不是数组?如何转化成数组?

Open su37josephxia opened this issue 3 years ago • 1 comments

su37josephxia avatar Feb 25 '22 01:02 su37josephxia

为什么

BE 本人说法是当时设计 arguments 的时候只花了十天时间整理设计的太糙了, 后来本来也打算改成真的 Array, 但是后来觉得多一事不如少一事又不改了

后来因为 ES 要向后兼容, 如果改动的话牵扯太大(兼容性), 就不改了

直到 ES6 终于对 arguments 提供了一个替代品 - rest parameters:

怎么转化

Array.from(arguments)
Array.prototype.slice.call(arguments) 

引用

https://blog.csdn.net/weixin_30430169/article/details/94832480

shangjunhao avatar Feb 28 '22 15:02 shangjunhao