Skip to content

Instantly share code, notes, and snippets.

@codylindley
Forked from nathansmith/module_pattern_init.js
Created January 15, 2010 05:30
Show Gist options
  • Save codylindley/277836 to your computer and use it in GitHub Desktop.
Save codylindley/277836 to your computer and use it in GitHub Desktop.
//
// Automatically calls all functions in APP.init
//
jQuery(document).ready(function() {
APP.go();
});
//
// Module pattern:
// http://yuiblog.com/blog/2007/06/12/module-pattern/
//
var APP = (function($) {
// For use only inside APP.
var private_var_one = 'foo';
var private_var_two = 'bar';
// Expose contents of APP.
return {
go: function(funcName) {
var call_automatically_one = function() {
// Called on page-load.
// Can still be called individually, via:
// APP.init.call_automatically_one();
}();
var call_automatically_two = function() {
// Called on page-load.
// Can still be called individually, via:
// APP.init.call_automatically_two();
}();
},
misc: {
call_specifically_one: function() {
// Must be called individually, via:.
// APP.misc.call_specifically_one();
},
call_specifically_two: function() {
// Must be called individually, via:.
// APP.misc.call_specifically_two();
}
}
};
// Pass in jQuery ref.
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment