Pattern Series #1 : Revealing Module Pattern
Mar 14, 2016
1) First we define a self executing function. This provides our new function scope and keeps all logic isolated to one spot.
2) Next we need to return a public api for our module. Object literals work wonders for this.
3) Since we now have a place for our public methods to be accessed from, we can start defining them.
4) Now that we have a functioning module, we can start breaking up our public methods into smaller, more portable, private methods. Since they exist within our isolated function scope, nothing but the public methods we expose can access them.
I’ve been using this pattern for almost as long as I’ve been a professional developer and have never had it lead me astray. When you need privacy for singleton objects, this is a great path to take. It’s stable, battle tested, and reliable in every which way.