Skip to content

Instantly share code, notes, and snippets.

@shobhitchittora
Last active April 15, 2018 13:58
Show Gist options
  • Save shobhitchittora/f04726d16f155019d72b35fc07365652 to your computer and use it in GitHub Desktop.
Save shobhitchittora/f04726d16f155019d72b35fc07365652 to your computer and use it in GitHub Desktop.
JS Design Patterns - MODULE - IIFE
// IIFE is an anonymous function which is called immediately.
const myModule = (function(){
// private
const name = "my module";
// public
return {
getName: function(){
console.log(name);
}
};
})();
console.log(myModule.name); // undefined
console.log(myModule.getName()); // "my module"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment