In this article, John Resig discusses this snippet for currying:
Function.prototype.curry = function() {
var fn = this, args = Array.prototype.slice.call(arguments);
return function() {
return fn.apply(this, args.concat(
Array.prototype.slice.call(arguments)));
};
};
I am confused about the expression Array.prototype.slice.call(arguments)
.
Here "arguments" is the "this" argument to Array's slice() method, but "slice()" requires an argument itself, so I would think you'd need to do something like
Array.prototype.slice.call(arguments, <someIndex>)
. I don't understand how that code can be working as is.According to the docs on "arguments", "arguments" is not actually an Array, but only an array like object. How are we calling "slice()" on it? And if I put in the code
console.log(arguments.slice())
I get an error saying that the object does not have a slice method.
What's going on here?