Skip to content

Instantly share code, notes, and snippets.

@prdanelli
Last active August 16, 2021 10:58
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 prdanelli/936b2c4c402b4aca8142 to your computer and use it in GitHub Desktop.
Save prdanelli/936b2c4c402b4aca8142 to your computer and use it in GitHub Desktop.
Example of Revealing module pattern in javascript
var myRevealingModule = (function () {
var privateCounter = 0;
function privateFunction() {
privateCounter++;
}
function publicFunction() {
publicIncrement();
}
function publicIncrement() {
privateFunction();
}
function publicGetCount(){
return privateCounter;
}
// Reveal public pointers to
// private functions and properties
return {
start: publicFunction,
increment: publicIncrement,
count: publicGetCount
};
})();
myRevealingModule.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment