Created
July 29, 2015 10:13
-
-
Save Bambina-zz/4d346dc94bc21a3b72a6 to your computer and use it in GitHub Desktop.
js curry function
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
//2つの引数を取る関数add(x,y)のカリー化 | |
function add(x,y){ | |
return x+y; | |
} | |
//これを引数を1つ取り、残りの引数を取って処理結果を返す関数に分解する。 | |
function add(x){ | |
return function(y){ //y1つを取る無名関数を返す。 | |
return x+y; | |
}; | |
}; | |
console.log(add(1)(2)); //=>3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment