Created
August 27, 2017 05:59
-
-
Save railsstudent/35821f4046a2aeebb682b6b3ac21bdc6 to your computer and use it in GitHub Desktop.
Practice how to create modular code using IIFE pattern
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
var NonsenseAPI = (function() { | |
var publicAPI = { | |
name, | |
gender, | |
profession, | |
languages | |
}; | |
function name(nickname) { | |
return 'John' + (nickname ? ' "' + nickname + '"' : '') + ' Doe'; | |
} | |
function gender() { | |
return 'male'; | |
} | |
function profession() { | |
return 'Front-end developer'; | |
} | |
function languages() { | |
return 'Cantonese, English'; | |
} | |
return publicAPI; | |
})(); | |
console.log(NonsenseAPI.name('I don\'t know anything')); | |
console.log(NonsenseAPI.gender()); | |
console.log(NonsenseAPI.languages()); | |
console.log(NonsenseAPI.profession()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment