Why apply () here takes only one argument instead of two?

I am reading a Javascript: The Good Parts book. And I am 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 nullto slice.apply(arguments)?

+5
source share
3 answers

argumentspassed as context ( this), not function arguments.

This is equivalent arguments.slice(), except that it arguments.slice()does not exist.

+5
source

This is the equivalent of calling slice()in an array with no arguments - i.e. it returns an array with all the elements of the original array. In this case, the “arguments” are not a true array, so calling Array.prototype.slice on it actually turns it into one.

+2
source

.

var slice = Array.prototype.slice,
args = slice.apply(arguments),

.

http://blog.sebarmeli.com/2010/11/12/understanding-array-prototype-slice-applyarguments/

Array.prototype.slice,, , .

In the second function, the function method is applied. The use and details of this function are well defined here http://www.devguru.com/technologies/ecmascript/quickref/apply.html

+1
source

All Articles