jQuery.later – a setTimeout wrapper in jQuery

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

Download

You can download it from my github page. It also includes a html page which tells you how to use it.

Syntax

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.

Parameters:
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.
Returns: object
a timer object. Call the cancel() method on this object to stop the timer.

License

Released under MIT License

PS: BTW this is my first jQuery Plugin. 🙂

Related posts

Tags: , ,

3 Comments so far

Follow up comments through RSS Feed | Post a comment

  • Raman says:

    Could you please show an example of how the “data” parameter in the function is to be wrapped in single or array formats, and called? I am new to javascript/jquery but see great potential in this plugin. Thanks.

  • Derek says:

    Could you release this under a license (MIT, GPL or public domain)? I would love to use it but can’t until its clear what the terms are.

    Thanks!

3 Tweetbacks so far

Leave a Reply

Your email address will not be published. Required fields are marked *