Created
June 12, 2020 12:34
-
-
Save oliverwebr/cd477910e14ac47032030ed203571b0b to your computer and use it in GitHub Desktop.
JS-Closures Example-1: Simpler APIs
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 createTranslation(lang) { | |
const dictionary = { | |
food: { | |
en: "food", | |
de: "essen", | |
}, | |
apple: { | |
en: "apple", | |
de: "apfel", | |
}, | |
}; | |
return function t(word) { | |
return dictionary[word][lang]; | |
}; | |
} | |
const en = createTranslation("en"); | |
const de = createTranslation("de"); | |
console.log(en("apple"), de("apple")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment