Created
November 12, 2019 21:06
-
-
Save jeanjmichel/4724d66eb312d148b2fb1bb913b36fde to your computer and use it in GitHub Desktop.
Currying em JavaScript é uma forma de fazer uma função receber parâmetros (que não necessariamente são todos os essenciais para a imediata execução da função) e retornar uma outra função.
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
const saudarPessoa = (saudacaoNoIdiomaX) => (nomePessoa) => console.log(`${saudacaoNoIdiomaX} ${nomePessoa}`); | |
const saudarEmIngles = saudarPessoa('Good morning'); | |
const saudarEmEspanhol = saudarPessoa('Buen día'); | |
const saudarEmAlemao = saudarPessoa('Guten Morgen'); | |
saudarEmIngles('John'); | |
saudarEmEspanhol('Juan'); | |
saudarEmAlemao('Jean'); | |
//É o mesmo que | |
/* | |
* const saudarPessoa = function (saudacaoNoIdiomaX) { | |
* return function (nomePessoa) { | |
* console.log(`${saudacaoNoIdiomaX} ${nomePessoa}`); | |
* } | |
* } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment