With the following line, .apply
is invoking the .call
method with the calling context of .call
being the .slice
method, and the arguments
collection passed as individual arguments.
Function.prototype.call.apply(Array.prototype.slice, arguments);
This effectively gives us this:
Array.prototype.slice.call(arguments[0], arguments[1], arguments[2] /*, etc */);
This means that .slice()
will be invoked with the first item in the arguments
object as the calling context, and the rest of the arguments as the normal arguments.
So if the content of arguments
is something like this:
myarray, 0, 5
You're effectively ending up with this:
myarray.slice(0, 5)
It's basically a way of not having to do this:
var arr = arguments[0];
var rest = Array.prototype.slice(arguments, 1);
var result = arr.slice.apply(arr, rest);