Created
January 10, 2019 07:18
-
-
Save apolopena/a22c78a3dbc0bdccbcb455b77c6b8158 to your computer and use it in GitHub Desktop.
Javascript Currying Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// currying example | |
var add = function(vala){ | |
return function(valb){ | |
return vala + valb; | |
} | |
} | |
console.log(add(2)(2)); // outputs 4 | |
// or more currying just not chained which is the same thing | |
var twoplus = add(2); | |
console.log(twoplus(2)); // outputs 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ES5 oneliner
var a=function(b){return function(c){return b+c;}};console.log(a(4)(4));//outputs 8