diff --git a/lib/moment-timer.js b/lib/moment-timer.js index 01fbe48..0e19145 100644 --- a/lib/moment-timer.js +++ b/lib/moment-timer.js @@ -14,6 +14,7 @@ function Timer(duration, attributes, callback) { this.timerDuration = duration; this.callback = callback; + this.args = attributes.args; this.loop = attributes.loop; this.started = false; this.stopped = false; // If stop() is called this variable will be used to finish the paused duration once it's started again. @@ -26,7 +27,7 @@ var self = this; setTimeout(function () { if (attributes.executeAfterWait) { - callback(); + callback(self.args); } self.start(); }, attributes.wait); @@ -44,7 +45,7 @@ // Takes care of restarts. If the timer has been stopped, this will make sure the leftover duration is executed. if (this.stopped) { setTimeout(function () { - self.callback(); + self.callback(self.args); return self.start(); }, this.getRemainingDuration()); @@ -63,6 +64,12 @@ return false; } + Timer.prototype.execute = function () { + var self = this; + + self.callback(self.args); + } + Timer.prototype.stop = function () { if (this.started) { this.clearTimer(); @@ -131,12 +138,12 @@ if (this.loop) { this.timer = setInterval(function () { self.updateStartEndTickFromDuration(self.timerDuration); - return self.callback(); + return self.callback(self.args); }, this.timerDuration); } else { this.timer = setTimeout(function () { self.started = false; - return self.callback(); + return self.callback(self.args); }, this.timerDuration); } }