Skip to content

Instantly share code, notes, and snippets.

@carldanley
Created August 22, 2013 16:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save carldanley/8453d2d1f910daa1b3dc to your computer and use it in GitHub Desktop.
Save carldanley/8453d2d1f910daa1b3dc to your computer and use it in GitHub Desktop.
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