Array.prototype.slice.call(arguments)

Array.prototype.slice.call(arguments)可以將具備length屬性的對象轉化爲數組,數組

能夠理解爲將arguments轉化成一個數組對象,讓它具備slice方法this

如:spa

function test(){
    console.log(Array.prototype.slice.call(arguments));
}
test(1,2);

Array是一個類,不能直接引用,須要獲取原型後才能使用。prototype

若是要直接引用,須要實例化arraycode

var array = new Array();

array.slice.call(arguments);

array.slice(start,end)對象

console.log([1,2,3].slice());
//[1, 2, 3]
console.log([1,2,3].slice(1,3));
//[2, 3]

call的做用是改變this的指向,至關於arguments調用了slice這方法blog

相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息