Skip to content

Instantly share code, notes, and snippets.

Created August 22, 2013 16:10
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Another example of the module pattern implementation in JS
var MyModule = ( function( window, undefined ) {
// this object is used to store private variables and methods across multiple instantiations
var privates = {};
function MyModule() {
this.myMethod = function myMethod() {
alert( 'my method' );
this.myOtherMethod = function myOtherMethod() {
alert( 'my other method' );
return MyModule;
} )( window );
// example usage
var myMod = new MyModule();
myMod.myMethod(); // alerts "my method"
myMod.myOtherMethod(); // alerts "my other method"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment