Created
May 16, 2018 13:48
-
-
Save Phoen1x84/da9daed246b091f1f7cdc0b437e7776d to your computer and use it in GitHub Desktop.
Example of the revealing module pattern
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
// 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