Skip to content

Instantly share code, notes, and snippets.

@skokasik
Forked from mdarnall/gist:807031
Last active December 25, 2015 23:19
Show Gist options
  • Save skokasik/7055683 to your computer and use it in GitHub Desktop.
Save skokasik/7055683 to your computer and use it in GitHub Desktop.
/*
A quick sample of the module pattern from JavaScript Patterns
*/
var app = app || {};
app.module = (function(){
// private members
var prop = 0;
//private functions
function myPrivateFunction(){
prop ++;
}
// public api
return {
myPublic : function() {
return prop;
},
myRevealingMethod : myPrivateFunction
}
})();
app.module.myPublic(); // 0
app.module.myRevealingMethod();
app.module.myPublic(); // 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment