Basically I want to do something like this:
$(document).ready(function() {
if ($(body).attr("class") === "HomePage") {
HomePage.init(); //bind events for home page (Crockford's module pattern)
} else if ($(body).attr("class") === "AboutPage") {
AboutPage.init(); //bind events for about page
}
});
The reason is so I can minify everything into one js file, thus reducing the number of http requests. This solution is definitely not elegant, since I need to add another 'else if' statement whenever I add new pages. I could use:
$(document).ready(function() {
eval($(body).attr("class") + ".init();");
});
But eval is evil and I don't know the performance implications using this method.