Created
August 31, 2016 05:30
-
-
Save leonardofaria/559eaf068d517ce77078aeb0550d51ae to your computer and use it in GitHub Desktop.
Javascript module loader
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
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)); |
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
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(); | |
} | |
} | |
}); |
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
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