Created
September 17, 2018 02:52
-
-
Save travishen/c76e14f209a5104dff66634cf9a64ca9 to your computer and use it in GitHub Desktop.
Create a factory using closure
This file contains hidden or 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
function makeGreeting(language) { | |
return function(name){ | |
if(language == 'en') console.log('Hello' + name); | |
if(language == 'es') console.log('Hola' + name); | |
} | |
} | |
var greetEnglish = makeGreeting('en'); | |
greetEnglish('John'); // Hello John |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment