Last active
June 24, 2016 06:52
-
-
Save etoxin/6aff9c07a764036caa84e0ec9fae4105 to your computer and use it in GitHub Desktop.
Revealing Namespace Module Loader
This file contains hidden or 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
/** | |
* 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 || {}); |
This file contains hidden or 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
// 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