Skip to content

Instantly share code, notes, and snippets.

@LongLiveCHIEF
Created August 3, 2014 21:32
Show Gist options
  • Save LongLiveCHIEF/62dbd02110dd468cf2c0 to your computer and use it in GitHub Desktop.
Save LongLiveCHIEF/62dbd02110dd468cf2c0 to your computer and use it in GitHub Desktop.
Module Pattern for creating a "step" and passing it handler functions
var step1 = new Step($elem);
// an example handler funciton
var highlightStep = function(){
this.$elem.addClass('highlight');
}
step1.addHandler(highlightStep);
// later in your code
step1.highlightStep();
var Step = (function(){
this.state = 'loading';
this.$elem = {};
this.getStatus = function(){
return this.state;
}
this.addHandler = function(handler, callback){
if(typeof handler === 'function'){
this.prototype['handler']['name'] = handler;
}
callback();
}
this.init = function($elem){
this.$elem = $elem;
return step;
}
var step = {
addHandler: addHandler,
removeHandler: removeHandler,
getStatus: getStatus
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment