Array.prototype.slice.call(arguments,1) 可以理解为:改变数组slice方法的作用域,使 this 指向arguments对象,call() 方法的第二个参数表示传递给slice的参数即截取数组的起始位置。Array.prototype.slice.call(arguments,1) 能够将具有length属性(这一点需要注意,必须包含length属性)的对象转换为数组。
//arguments
function fn(){
console.log(Array.prototype.slice.call(arguments,1));//["e"]
console.log(arguments.slice(1))//报错
}
fn(1,'e')
//有length属性的对象,键名不能改
let obj = {0:'h',1:'i',length:2};
console.log(Array.prototype.slice.call(obj,0));//["h", "i"]
//没有length属性的对象
let obj2 = {0:'h',1:'i'};//没有length属性
console.log(Array.prototype.slice.call(obj2,0));//[]