Skip to content

Instantly share code, notes, and snippets.

@branneman
Last active June 15, 2016 13:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save branneman/eecdb75c1c963215c746 to your computer and use it in GitHub Desktop.
Save branneman/eecdb75c1c963215c746 to your computer and use it in GitHub Desktop.
Conditioner.js blueprint module
/**
* @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