Because of this, closures are required to produce useful code. Without the need for closures, these methods could be stored inside the class rather than inside the calling method which would produce a more modular and object oriented style of coding.
Here are some key features of "jQuery timers":
· Abstracted Timer IDs - When you call setTimeout or setInterval with the intention of possibly stopping it later on you need to save the reference to the timer id. This is really cumbersome especially when you want loosely coupled activation deactivation of events. This plugin fixes that by storing the timer id internally and using it behind the scenes when stopping events.
· Labelled Events - When you create a timed event, you have the option of giving it a label. These labels allow for multiple timed events to operate on the same object with fine control over which method you want to stop.
· Limited Events - Beyond simply running once in a given amount of time and running every given amount of time, sometimes there is a need to run at a given time interval but only for a certain number of times.
· Intelligent Event Belay - Sometimes when you have an event which is supposed to run every 500 milliseconds but every so often the function the event calls happens to take 600 milliseconds. jQuery timers lets you belay an instance of the event if the previous event is still running. This is disabled by default.
· String Time Parsing - Too often, people try to use setTimeout or setInterval to do something every second but forget that they both take milliseconds. jQuery timers allows you to specify your time as a string. It include the SI prfixed time values for 'ms', 'cs', 'ds', 's', 'das', 'ws', and 'ks' which may be overkill but because milliseconds and seconds were already being added, the others were trivial to implement.