Last active
August 16, 2021 10:58
-
-
Save prdanelli/936b2c4c402b4aca8142 to your computer and use it in GitHub Desktop.
Example of Revealing module pattern in javascript
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
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