Basically I want to do something like this:
$(document).ready(function() { if ($(body).attr("class") === "HomePage") { HomePage.init(); //bind events for home page (Crockford module pattern) } else if ($(body).attr("class") === "AboutPage") { AboutPage.init(); //bind events for about page } });
The reason is that I can minimize everything to a single js file, thereby reducing the number of HTTP requests. This solution is certainly not elegant, as I need to add another else expression if I add new pages. I could use:
$(document).ready(function() { eval($(body).attr("class") + ".init();"); });
But eval is evil, and I do not know the results associated with this method.
jquery design-patterns
Systemr
source share