Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
-1
rated 0 times [  5] [ 6]  / answers: 1 / hits: 96115  / 15 Years ago, tue, february 16, 2010, 12:00:00

I want to make this syntax possible:



var a = add(2)(3); //5


based on what I read at http://dmitry.baranovskiy.com/post/31797647



I've got no clue how to make it possible.


More From » currying

 Answers
31

You need add to be a function that takes an argument and returns a function that takes an argument that adds the argument to add and itself.



var add = function(x) {
return function(y) { return x + y; };
}

[#97559] Friday, February 12, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaredsages

Total Points: 273
Total Questions: 97
Total Answers: 105

Location: French Southern and Antarctic Lands
Member since Fri, Jan 6, 2023
1 Year ago
jaredsages questions
;