Created
November 5, 2013 02:55
-
-
Save curtis1000/7313098 to your computer and use it in GitHub Desktop.
A Simple JS Module Structure
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
/** | |
* @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