| 
39 
29 | 
I know it is used to make arguments a real array, but I don't understand what happens when using prototype.slice.call(arguments) | |||
| 
 | 
| 
74 | 
What happens under the hood is that when  .slice()is called normally,thisis an Array, and then it just iterates the Array, and does its work.
How is  thisin the.slice()function an Array? Because when you do:
...the  objectautomatically becomes the value ofthisin themethod(). So with:
...the  [1,2,3]Array is set as the value ofthisin.slice().
But what if you could substitute something else as the  thisvalue? As long as whatever you substitute has a numeric.lengthproperty, and a bunch of properties that are numeric indices, it should work. This type of object is often called an array-like object.
The  .call()and.apply()methods let you manually set the value ofthisin a function. So if we set the value ofthisin.slice()to an array-like object,.slice()will just assume it's working with an Array, and will do its thing.
Take this plain object as an example. 
This is obviously not an Array, but if you can set it as the  thisvalue of.slice(), then it will just work, because it looks enough like an Array for.slice()to work properly.
Example: http://jsfiddle.net/wSvkv/ 
As you can see in the console, the result is what we expect: 
So this is what happens when you set an  argumentsobject is thethisvalue of.slice(). Becauseargumentshas a.lengthproperty and a bunch of numeric indices,.slice()just goes about its work as though it was working with an Array. | ||||||
| 
 | 
| 
1 | 
I'm just writing this to remind myself... 
Or just use this handy function $A to turn most things into an array. 
example usage...  | ||
| 
1 | 
Dont forget, that a low-level basics of this behaviour is the type-casting that integrated in JS-engine entirely. 
Slice just takes object (thanks to existing arguments.length property) and returns array-object casted after doing all operations on that. 
The same logics you can test if you try to treat String-method with an INT-value: 
And that explains statement above. | |||
| 
7 | 
The  argumentsobject is not actually an instance of an Array, and does not have any of the Array methods. So,arguments.slice(...)will not work because the arguments object does not have the slice method.
Arrays do have this method, and because the  argumentsobject is very similar to an array, the two are compatible. This means that we can use array methods with the arguments object. And since array methods were built with arrays in mind, they will return arrays rather than other argument objects.
So why use  Array.prototype? TheArrayis the object which we create new arrays from (new Array()), and these new arrays are passed methods and properties, like slice. These methods are stored in the[Class].prototypeobject. So, for efficiency sake, instead of accessing the slice method by newArray().slice.call()or[].slice.call(), we just get it straight from the prototype. This is so we don't have to initialise a new array.
But why do we have to do this in the first place? Well, as you said, it converts an arguments object into an Array instance. The reason why we use slice, however, is more of a "hack" than anything. The slice method will take a, you guessed it, slice of an array and return that slice as a new array. Passing no arguments to it (besides the arguments object as its context) causes the slice method to take a complete chunk of the passed "array" (in this case, the arguments object) and return it as a new array. | |||
| 
 | 
| 
0 | 
Its because, as MDN notes 
 
Here we are calling  sliceon the native objectArrayand not on its implementation and thats why the extra.prototype | ||
| 
0 | 
Let's assume you have:  function.apply(thisArg, argArray )
 
The slice() method selects a part of an array, and returns the new array. 
So when you call  Array.prototype.slice.apply(arguments, [0])the array slice method is invoked (bind) on arguments. | ||
| 
2 | 
Normally, calling 
will copy the array  aintob. However, we can't do
because  argumentsisn't a real array, and doesn't havesliceas a method.Array.prototype.sliceis theslicefunction for arrays, andcallruns the function withthisset toarguments. | ||||||
| 
 | 
| 
0 | 
It uses the  slicemethod arrays have and calls it with itsthisbeing theargumentsobject. This means it calls it as if you didarguments.slice()assumingargumentshad such a method.
Creating a slice without any arguments will simply take all elements - so it simply copies the elements from  argumentsto an array. | ||
