Skip to content

Instantly share code, notes, and snippets.

@etoxin
Last active June 24, 2016 06:52
Show Gist options
  • Save etoxin/6aff9c07a764036caa84e0ec9fae4105 to your computer and use it in GitHub Desktop.
Save etoxin/6aff9c07a764036caa84e0ec9fae4105 to your computer and use it in GitHub Desktop.
Revealing Namespace Module Loader
/**
* project.exampleModule
* @namespace project.exampleModule
*/
(function (window, project, undefined) {
/**
* @constructor
* @public
* @memberof project.exampleModule
*/
function initiateModule() {
console.log('Hello World');
}
/**
* Define the namespace and module name
* Expose `init` to the module loader.
* @memberof project
*/
project.exampleModule = {};
project.exampleModule.init = initiateModule;
})(window, window.project = window.project || {});
// Project Module Loader.
/**
* ready Function
*/
function ready(fn) {
if (document.readyState != 'loading'){
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
ready(function(){
/**
* Module Initiator
* Make sure the module has a `init()` function exposed. If so -> initiate.
*/
for (var module in project) {
if('init' in project[module]){
project[module].init();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment