Created
April 26, 2014 17:36
-
-
Save joewagner/11326170 to your computer and use it in GitHub Desktop.
A class that runs a function on an interval. An instance of this class can be passed to many controllers, but only one interval will ever be set.
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 RingOfPower = function (action, freq) { | |
if (typeof action === "undefined" || typeof freq === "undefined") { | |
throw new Error("must provide a function and an interval"); | |
} | |
this.action = action; | |
this.frequency = freq; | |
}; | |
RingOfPower.prototype.wield = function () { | |
clearInterval(this.interval); | |
this.interval = setInterval(this.action, this.frequency); | |
}; | |
RingOfPower.prototype.conceal = function () { | |
clearInterval(this.interval); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment