Skip to content

Instantly share code, notes, and snippets.

@Phoen1x84
Created May 16, 2018 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Phoen1x84/da9daed246b091f1f7cdc0b437e7776d to your computer and use it in GitHub Desktop.
Save Phoen1x84/da9daed246b091f1f7cdc0b437e7776d to your computer and use it in GitHub Desktop.
Example of the revealing module pattern
// ES5 example
var module = (function() {
'use strict';
var selectors = {
// object literal would contain selectors
mySelector: '.banner'
};
var publicMethod = function() {
console.log("I'm a public function you should see me in console, i can be called by typing module.publicMethod()");
};
var privateMethod = function() {
console.log("I'm a private function you should see me in console but cannot access me via a function");
};
var init = function() {
privateMethod();
};
return {
init: init,
publicMethod: publicMethod
};
})();
module.init(); // I'm a private function you should see me in console but cannot access me via a function
module.publicMethod() // I'm a public function you should see me in console, i can be called by typing module.publicMethod()
module.privateMethod() // module.privateMethod is not a function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment