Skip to content

Instantly share code, notes, and snippets.

@mdarnall
Created February 2, 2011 00:39
Show Gist options
  • Save mdarnall/807031 to your computer and use it in GitHub Desktop.
Save mdarnall/807031 to your computer and use it in GitHub Desktop.
Object Creation Pattern
/*
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