en.javascript.info/1-js/06-advanced-functions/03-closure/4-closure-sum/solution.md
Ilya Kantor ab9ab64bd5 up
2017-03-21 14:41:49 +03:00

268 B

For the second brackets to work, the first ones must return a function.

Like this:

function sum(a) {

  return function(b) {
    return a + b; // takes "a" from the outer lexical environment
  };

}

alert( sum(1)(2) ); // 3
alert( sum(5)(-1) ); // 4