Last active
August 5, 2017 23:12
-
-
Save carldanley/ef95b006eaa08761b0ca to your computer and use it in GitHub Desktop.
Example of the Revealing Module Pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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