Skip to content

Instantly share code, notes, and snippets.

@redsquare
Created June 29, 2011 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redsquare/1053873 to your computer and use it in GitHub Desktop.
Save redsquare/1053873 to your computer and use it in GitHub Desktop.
js encapsulation template - better minification
//
// Module pattern:
// http://yuiblog.com/blog/2007/06/12/module-pattern
//
var APP = (function($, window, document, undefined) {
// For use only inside APP.
var PRIVATE_CONSTANT_1 = 'foo';
var PRIVATE_CONSTANT_2 = 'bar';
// Expose contents of APP.
return {
go: function() {
for (var i in APP.init) {
APP.init[i]();
}
},
init: {
call_automatically_one: function() {
// Called on page-load.
// Can still be called individually, via:
// APP.init.call_automatically_one();
},
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();
}
}
};
// Alias jQuery, window, document.
})(this.jQuery, this, this.document);
//
// Automatically calls all functions in APP.init
//
jQuery(document).ready(function() {
APP.go();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment