Created
June 21, 2012 17:44
-
-
Save jmontross/2967292 to your computer and use it in GitHub Desktop.
Javascript module pattern with a closure
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 awesomeModule = (function () { | |
var privateVariable; | |
function privateFunction() { | |
//do something; | |
} | |
return { // <----- this starts the object being returned when this module function executes | |
init: function () { | |
// I have access to privateVariable & privateFunction | |
} // init | |
}; // <----- this ends the object being returned when this module function executes | |
})(); | |
// to Load this guy on dom loaded with prototype | |
// document.observe('dom:loaded', awesomeModule.init); | |
// to load this guy with jquery | |
// $(document).ready(function(){ awesomeModule.init(); }) | |
// more module patterns http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment