Created
February 10, 2012 06:26
Javascript Boilerplate Structure with Closures
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
//define a global object where to put all our code | |
//this is an immediate calling function | |
window.APP = (function(){ | |
//create an object that will be returned | |
var that = {}; | |
//private methods | |
function init(){ | |
APP.registrationController.init(); | |
APP.galleryController.init(); | |
}; | |
//public properties | |
that.foo = true; | |
//expose public methods | |
that.init = init; | |
return that; | |
}()); | |
//define other controllers as needed | |
APP.registrationController = (function(){ | |
//same structure as APP | |
var that = {}; | |
function init(){ | |
//... | |
} | |
that.init = init; | |
return that; | |
}()); | |
app.galleryController = (function(){ | |
//same | |
}()); | |
//jquery dom ready | |
$(function(){ | |
//in here just call APP init and nothing else | |
APP.init(); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment