Constructing
// Basic
var timer = new Timer(1000, function () {
console.log("Tick Tac!");
});
// Call the callback imediatelly
var timer = new Timer(1000, function () {
console.log("Tick Tac!");
}).execute();
The property count
holds the count of how many times the callback was trigged
console.log(timer.count);
Property isRunning
holds whether the timer is running or not
console.log(timer.count);
stop
, start
and restart
methods
// Stop the timer. If pass argument 'true' it will reset the counter
timer.stop();
timer.stop(true);
// Start the timer
timer.start();
// Restart the timer. Same as timer.stop(true).start()
timer.restart();
execute
will call the timer callback. It accepts an boolean argument that indicates whether the timer should be restarted or not
// Call the timer callback
timer.execute();
// Call the timer callback and restart the timer count
timer.execute(true);
setInterval
and setCallback
will set the new values at runtime
// Sets a new interval for the timer
timer.setInterval(2000);
// Sets a new callback for the timer
timer.setCallback(function () {
console.log("Tac Tick!");
});