Skip to content

Instantly share code, notes, and snippets.

@slowmove
Last active August 29, 2015 14:18
Standard JS file structure
var MainScript = {
init: function() {
/**
* Init all Objects
*/
for (var n in this) {
if ( typeof(this[n].init) === 'function' ){
this[n].init();
}
}
},
siteWide: {
init: function() {
this.setListeners();
},
setListeners: function() {
}
},
startPage: {
init: function() {
var isStartPage = document.querySelector('body.start');
if(!isStartPage)
return;
this.setListeners();
},
setListeners: function() {
}
}
}
document.addEventListener("DOMContentLoaded", function() {
MainScript.init();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment