Recently I have been playing around with YUI 3 and found that it had a nice wrapper for setTimeout/setInterval which nicely encapsulated it.
I thought it would be nice to have a wrapper like that for jQuery, which led to this nice little Plugin for jQuery called jQuery Later
You can download it from my github page. It also includes a html page which tells you how to use it.
jQuery later function follows the same syntax as that of YUI.
jQuery.later ( when , o , fn , data , periodic )
Executes the supplied function in the context of the supplied object ‘when’ milliseconds later. Executes the function a single time unless periodic is set to true.
when <int>the number of milliseconds to wait until the fn is executed.
o <object>the context object.
fn <Function|String>the function to execute or the name of the method in the ‘o’ object to execute.
data <object>[Array] data that is provided to the function. This accepts either a single item or an array. If an array is provided, the function is executed with one parameter for each array item. If you need to pass a single array parameter, it needs to be wrapped in an array [myarray].
periodic <boolean>if true, executes continuously at supplied interval until canceled.
- a timer object. Call the cancel() method on this object to stop the timer.
Released under MIT License
PS: BTW this is my first jQuery Plugin. 🙂