I'm reading the book Javascript: The Good Parts. And I'm confused by the following code.
Function.method('curry', function (  ) {
    var slice = Array.prototype.slice,
        args = slice.apply(arguments),
        that = this;
    return function (  ) {
        return that.apply(null, args.concat(slice.apply(arguments)));
    };
});
Where is the null in slice.apply(arguments)?
arguments is being passed as the context (this), not the function's arguments.
It's equivalent to arguments.slice(), except that arguments.slice() doesn't exist.
That's the equivalent of calling slice() on an array with no arguments - i.e. it returns an array with all the elements of the original array. In this case, 'arguments' is not a true array, so calling Array.prototype.slice on it in effect turns it into one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With