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

前端 未结 3 826
无人共我
无人共我 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条回答
  •  感动是毒
    2020-12-07 12:00

    As BoltClock says, it makes a (shallow) copy of an array. It can also be used to copy something that is almost an array, such as the arguments builtin, which has a length and items but no Array in its prototype chain (and hence no slice method).

提交回复
热议问题