In the context of inside a function, here's the code (based on the standard pattern of making a function's 'arguments' into an array):
var args = Array.prototype.slice.call(arguments);
I'm trying to study this out (am a beginner at JavaScript, coming from C#).
I understand that slice
is an instance method due to it being a prototype
function of Array.
I also understand that this is not a static 'utility function', meaning to use it, you have to new
it up like so: (example) var myArray = new Array(); myArray.slice(...);
call
passes an object in here to change the context to that of arguments
Related to this, I don't also know the difference between
Array.prototype.slice.call([32,32,121,412])
and Array.prototype.slice([32,32,121,412])
not in the context of call
.
So, here's my question:
I just don't get how this works in relation to instance vs static methods... so can anyone explain the intricacies of var args = Array.prototype.slice.call(arguments);
?
Why can this be used without calling new
?
Why was this possible? It's not a Static method, and it must be 'newed' up, and it only works when you use call
function... (at least in my C# mentality...)