Skip to content

Instantly share code, notes, and snippets.

@kayue
Created April 12, 2011 18:51
Show Gist options
  • Save kayue/916127 to your computer and use it in GitHub Desktop.
Save kayue/916127 to your computer and use it in GitHub Desktop.
Javascript bootstrapping
/**
* Namespacing
* All method start with "init" will be automatically called at start.
*/
var popbee = {}
popbee.body = $("body");
popbee.initHomepage = function() {
if(!popbee.body.hasClass("homepage") return; // return if not at homepage
alert("only pop if (and only if) this is homepage");
}
popbee.shorthand = function() {
// this won't call
}
// dom ready
$(function(){
// start initial the page
var namespace = popbee;
for(method in namespace) {
// skip if not start with _init
if(method.toString().substring(0,4) !== 'init') continue;
// call method
namespace[method.toString()]();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment