Last active
June 15, 2016 13:26
-
-
Save branneman/eecdb75c1c963215c746 to your computer and use it in GitHub Desktop.
Conditioner.js blueprint module
This file contains hidden or 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
/** | |
* @module MyModule | |
*/ | |
define(['dep1'], function(dep1) { | |
"use strict"; | |
/** | |
* @param {HTMLElement} element | |
* @param {Object} options | |
* @constructor | |
*/ | |
function MyModule(element, options) { | |
this._element = element; | |
this._options = options; | |
this.load(); | |
} | |
/** | |
* Base options | |
*/ | |
MyModule.options = {}; | |
/** | |
* Construct module | |
*/ | |
MyModule.prototype.load = function() { | |
this.setExecutionContext(); | |
this.bindEvents(); | |
}; | |
/** | |
* Module unload | |
*/ | |
MyModule.prototype.unload = function() { | |
this.unbindEvents(); | |
}; | |
/** | |
* Bind execution context to instanced `this` for all `onX` functions | |
*/ | |
MyModule.prototype.setExecutionContext = function() { | |
for (var prop in this) { | |
if (MyModule.prototype.hasOwnProperty(prop) | |
&& typeof this[prop] === 'function' | |
&& prop.substr(0, 2) === 'on') { | |
this[prop] = this[prop].bind(this); | |
} | |
} | |
}; | |
/** | |
* Add event listeners | |
*/ | |
MyModule.prototype.bindEvents = function() {}; | |
/** | |
* Remove event listeners | |
*/ | |
MyModule.prototype.unbindEvents = function() {}; | |
// Exports | |
return MyModule; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment