Skip to content

Instantly share code, notes, and snippets.

@StefanWallin
Created October 8, 2015 10:27
Show Gist options
  • Save StefanWallin/e47b49c200e553c4801f to your computer and use it in GitHub Desktop.
Save StefanWallin/e47b49c200e553c4801f to your computer and use it in GitHub Desktop.
Javascript jQuery namespaced functionality nugget
document.mittmedia = document.mittmedia || {};
(function(object, jQuery, ...dependencies...){
object.plugin_name = {
elements: {
},
init: function(){
this.gatherElements()
this.bindEventHandlers()
},
gatherElements: function(){
this.elements = {
label: {
abcd: $("#abcd")
...
},
error_label: {
...
},
input: {
...
},
button: {
...
}
}
},
bindEventHandlers: function(){
this.elements.label.abcd.on('click', handleLabelClick);
this.elements.label.defg.on('click', handleLabelClick);
...
}
...logic...
};
object.plugin_name.init();
})(document.mittmedia, jQuery, ...dependencies...);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment