Skip to content

Instantly share code, notes, and snippets.

@curtis1000
Created November 5, 2013 02:55
Show Gist options
  • Save curtis1000/7313098 to your computer and use it in GitHub Desktop.
Save curtis1000/7313098 to your computer and use it in GitHub Desktop.
A Simple JS Module Structure
/**
* @fileOverview Boilerplate Module
* @version 2.0
* @depends $ jQuery
*/
/**
* Module definition, wrapped in a closure, any dependencies are passed in
*/
(function ($) {
'use strict';
var enabled = false;
var Boilerplate = {
/**
* Initialize module, cache jquery objects
*/
init: function() {
// cache jQuery objects here
if (! enabled) {
this.enable();
}
},
/**
* Enable module, setup event handlers
* @returns {*}
*/
enable: function() {
if (enabled) {
return this;
}
enabled = true;
// setup event handlers here
},
/**
* Disable module, tear down event handlers
* @returns {*}
*/
disable: function() {
if (! enabled) {
return this;
}
enabled = false;
// turn off event handlers here
return this;
}
};
// fire this thing up
Boilerplate.init();
})(window.jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment