Array.prototype.slice.apply(arguments) 的含义
参考答案
把 slice 方法借给 arguments 使用,得到一个真正的数组(浅拷贝)。
拆解:
slice内部只依赖length与数字索引,因此可以作用在类数组上;.apply(arguments)把 arguments 作为 this 传入(同时可传参区间);- 效果等价
Array.from(arguments)/[...arguments]。
用途:ES6 前把 arguments 转数组以使用数组方法;现代可直接用 rest 参数 (...args)。