Timer

Timer objects allow you to perform a task at a periodic interval or can be used to simply fire once at a later time.
They allow you to create multiple timers all running on different frequencies.

They can also be started and stopped without having to delete them.

new Timer(interval, callback)

Parameters:

Name Type Description
interval Number

Time in seconds.

callback function

Method to execute when the timer triggers.

Properties:
Name Type Description
ticking Boolean

This allows you to turn a timer on and off by setting it to true and false, respectively.

If you want to disable a timer for a while, just set ticking to false.
Later, set it to true, and it starts firing again.

Methods

reset()

Resets the interval of the timer.

start()

This allows you to start running the timer.

stop()

This allows you to stop running the timer.