// This global variable will hold all your page specific functions // I know that global vars suck, but I think this is a good and safe exception MY_APP = { }; UTIL = { exec: function( controller, action ) { var ns = MY_APP, action = ( action === undefined ) ? "init" : action; if ( controller !== "" && ns[controller] && typeof ns[controller][action] == "function" ) { ns[controller][action](); } }, init: function() { var body = document.body, controller = body.getAttribute( "data-controller" ), action = body.getAttribute( "data-action" ); UTIL.exec( controller ); UTIL.exec( controller, action ); } }; $( document ).ready( UTIL.init );