Skip to content

Instantly share code, notes, and snippets.

@gwokae
Created March 1, 2012 04:09
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 gwokae/1947216 to your computer and use it in GitHub Desktop.
Save gwokae/1947216 to your computer and use it in GitHub Desktop.
A simple Javascript Module Pattern
var myObject = (function(){
var _private = {
someVar: "This is private",
privateFunction = function(){ /* do-something*/ };
}
return {
publicVar : "This is public",
publicFunction : function(){
/*do-something*/
},
getSomeVar: function(){
return _private.someVar;
}
}
}());
myObject._private /* undefined */
myObject.getSomeVar() /* returns "This is private" */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment