Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Javascript module loader
var App = App || {};
App.About = (function(document) {
'use strict';
var init = function() {
console.log('about init called()');
};
// Return all public methods
return {
init: init
};
}(window.document));
var App = App || {};
// If you use jQuery
$(document).ready(function() {
for (var module in App) {
if('init' in App[module]){
console.log('loading module: ' + module);
App[module].init();
}
}
});
// If you prefer vanilla JS
document.addEventListener('DOMContentLoaded', function() {
for (var module in App) {
if('init' in App[module]){
console.log('loading module: ' + module);
App[module].init();
}
}
});
var App = App || {};
App.Contact = (function (document, $) {
'use strict';
var init = function() {
console.log('contact init called()');
};
// Return all public methods
return {
init: init
};
}(window.document, window.$));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment