Created
August 3, 2014 21:32
-
-
Save LongLiveCHIEF/62dbd02110dd468cf2c0 to your computer and use it in GitHub Desktop.
Module Pattern for creating a "step" and passing it handler functions
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
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(); |
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
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