javascript 'curry', need some explanations on this code -


I read the book "Javascript-The Good Parts", in chapter 4.14 Curry, the book gives the following example:

  function.math ('curry', function () {var slice = array.prototype.Salis, args = slice.apple (arguments), // first-arguments = this; return function () {Return.apply (null, args.concat (slice.apply (argument)); // 2-arguments}} var add1 = add.curry (1); document.writeln (add1 (6)); // < 7>   

I have two questions on this code:

  1. ' A is used by using . In the method used in the previous two lines of code, this is because ' 1 ' goes to the 1-argument and ' 6 '2-goes in the beginning? / P>

  2. A line of code is Apply (Null, arguments. (Slice application (argument)) < / Code>, why this applies to (zero, ...) here ?, what is the meaning of applying logic for a null object?

    There are two places using arguments. In the method used in the previous two lines of code, it is because '1' goes to start 1-and '6' goes into 2-arrays?

    Yes, 1 is part of the argument of the external function, while 6 in the internal function goes to logic . The internal function can close all the variables except the logic and it , which has a special meaning inside the function, so it is not part of the shutdown. Therefore that , and args have been captured, but arguments no.

    There is a line of code implementation (faucet, weird argument (slice.apply (argument)), why this applies (empty, ...) here ?, a null What is the meaning of applying an argument for the object?

    By including a method with an empty reference, the global object will be set to this value. In the case it seems that the author does not care what the context is.

Comments