What's the use of Array.prototype.slice.call(array, 0)?

前端 未结 3 818
无人共我
无人共我 2020-12-07 11:30

I was just browsing Sizzle\'s source code and I came across this line of code:

array = Array.prototype.slice.call( array, 0 );

I looked up

3条回答
  •  Happy的楠姐
    2020-12-07 11:52

    What's happening here is that Sizzle is creating an actual array out of an array-like object. The array-like object doesn't necessarily have the slice() method, so the prototype method has to be called directly. makeArray() returns a copy of that array-like object that is an actual array, and can be used as such else where.

    See here for more information about array-like objects.

提交回复
热议问题