Skip to content

Instantly share code, notes, and snippets.

@aokolish
Created November 10, 2011 04:49
Show Gist options
  • Save aokolish/1354144 to your computer and use it in GitHub Desktop.
Save aokolish/1354144 to your computer and use it in GitHub Desktop.
Run page JS without switch statement
var LTD = {};
LTD.product = (function() {
//private functions
function somethingHandy() {
...
}
return {
//public functions...
init: function () {
//event handlers and such...
}
}
})();
LTD.global = (function() {
//same idea as LTD.product
...
})();
$(function() {
var location = $('body').attr("id").split("-"),
section = location[0],
subsection = location[1];
//always run global stuff
LTD.global.init();
//run code for the relevant page
LTD[section].init();
LTD[section][subsection].init();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment