Last active
June 26, 2018 07:22
-
-
Save travishen/56dac1acbdebeed9cd0c19124e7b56a9 to your computer and use it in GitHub Desktop.
in JavaScript, functions are objects, so there is actually no overloading, but we can do encapsulations like this
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
function greet(firstname, lastname, language) { | |
language = language || 'en'; | |
if (language === 'en') { | |
console.log('Hello ' + firstname + ' ' + lastname); | |
} | |
if (language === 'es') { | |
console.log('Hola ' + firstname + ' ' + lastname); | |
} | |
} | |
function greetEnglish(firstname, lastname) { | |
greet(firstname, lastname, 'en'); | |
} | |
function greetSpanish(firstname, lastname) { | |
greet(firstname, lastname, 'es'); | |
} | |
greetEnglish('John', 'Doe'); | |
greetSpanish('John', 'Doe'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment