Skip to content

Instantly share code, notes, and snippets.

@kevinpang
Created June 8, 2011 22:24
Show Gist options
  • Save kevinpang/1015589 to your computer and use it in GitHub Desktop.
Save kevinpang/1015589 to your computer and use it in GitHub Desktop.
JavaScript module pattern template
var myNamespace = (function(){
// Private variables / methods
var myPrivateVar = 0;
var myPrivateMethod = function(someText){
console.log(someText);
}
// Public variables / methods
return {
myPublicVar: "foo",
myPublicFunction: function(bar){
myPrivateVar++;
myPrivateMethod(bar);
}
}
})();
myNamespace.myPublicVar = "blah"; // OK
myNamespace.myPublicFunction("test") // OK
@kevinpang
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment