Skip to content

Instantly share code, notes, and snippets.

@E1101
Last active August 29, 2015 14:06
Show Gist options
  • Save E1101/1674cfba2d7cd843e785 to your computer and use it in GitHub Desktop.
Save E1101/1674cfba2d7cd843e785 to your computer and use it in GitHub Desktop.
js module skeleton
// initially you create your main application module that will
// load all his child modules
myapp = (function ($) {
'use strict';
var pub = {
initModule: function (module) {
if (module.isActive === undefined || module.isActive) {
if ($.isFunction(module.init)) {
module.init();
}
$.each(module, function () {
if ($.isPlainObject(this)) {
pub.initModule(this);
}
});
}
},
init: function () {
// common for all you project javascript logic
initLayoutComponents();
// whatever you want
}
};
// define private functions
function initLayoutComponents() {
}
return pub;
})(jQuery);
jQuery(document).ready(function () {
myapp.initModule(myapp);
});
// in other files you can define child modules
if (typeof myapp == "undefined" || !myapp) {
var myapp = {};
}
myapp.post = (function ($) {
var pub = {
isActive: true,
init: function () {
initPostComments()
},
}
function initPostComments() {
}
return pub;
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment