Last active
August 29, 2015 14:06
-
-
Save E1101/1674cfba2d7cd843e785 to your computer and use it in GitHub Desktop.
js module skeleton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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