JavaScript the Good Parts: unshift function -
i'm reading javascript:the parts crockford , i'm having problem understanding reimplementation of unshift
method in book.here the code:
array.method('unshift', function ( ) { this.splice.apply(this, [0, 0].concat(array.prototype.slice.apply(arguments))); homecoming this.length; });
it useful if go through happening step step. 1 of things don't understand why concatenates [0 , 0] result of array.prototype.slice
.
why concatenates [0 , 0] result of array.prototype.slice
the first 2 arguments of splice
(which resulting array applied to) are:
index
0
because adding front end of array howmany
(to remove) 0
because adding new elements the remaining arguments values added front end of array, taken array.prototype.slice.apply(arguments)
(to convert info arguments
object info in array).
javascript
No comments:
Post a Comment