Skip to content

Instantly share code, notes, and snippets.

@carldanley
Last active August 5, 2017 23:12
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save carldanley/ef95b006eaa08761b0ca to your computer and use it in GitHub Desktop.
Save carldanley/ef95b006eaa08761b0ca to your computer and use it in GitHub Desktop.
Example of the Revealing Module Pattern
var MyModule = ( function( window, undefined ) {
function myMethod() {
alert( 'my method' );
}
function myOtherMethod() {
alert( 'my other method' );
}
// explicitly return public methods when this object is instantiated
return {
someMethod : myMethod,
someOtherMethod : myOtherMethod
};
} )( window );
// example usage
MyModule.myMethod(); // undefined
MyModule.myOtherMethod(); // undefined
MyModule.someMethod(); // alerts "my method"
MyModule.someOtherMethod(); // alerts "my other method"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment