Skip to content
This repository was archived by the owner on Jun 3, 2018. It is now read-only.

Commit c039659

Browse files
committed
improve documentation
1 parent 60efa16 commit c039659

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# [jQuery Timeout Plugin](https://github.com/tkem/jquery-timeout/)
22

3-
**jQuery 1.5** introduced the _Deferred_ callback management system,
4-
to ease handling callbacks for asynchronous events. Although the
5-
jQuery documentation contains examples on how to use Deferred objects
6-
with the native `window.setTimeout` and `window.clearTimeout`
3+
**jQuery 1.5** introduced the [Deferred
4+
Object](http://api.jquery.com/category/deferred-object/) to ease
5+
handling callbacks for asynchronous events. Although the jQuery
6+
documentation contains examples on how to use Deferred objects with
7+
the native `window.setTimeout()` and `window.clearTimeout()`
78
functions, jQuery does not provide a simple interface for timer-based
89
Deferreds yet.
910

10-
This plugin provides the two functions `jQuery.timeout` and
11-
`jQuery.timeoutWith` that, given a delay in milliseconds, create a
11+
This plugin provides the two functions `jQuery.timeout()` and
12+
`jQuery.timeoutWith()` that, given a delay in milliseconds, create a
1213
`jQuery.Deferred` instance that will be resolved after the given
13-
delay. The returned Promise object also provides `clear` and
14-
`clearWith` methods, which will reject the Deferred object and clear
14+
delay. The returned Promise object also provides `clear()` and
15+
`clearWith()` methods, which will reject the Deferred object and clear
1516
the native timeout ID, if called before the timeout has elapsed.
1617

1718

@@ -21,24 +22,32 @@ the native timeout ID, if called before the timeout has elapsed.
2122

2223
Create a Deferred object that will be resolved after the specified
2324
`delay` in milliseconds. When the Deferred is resolved, any
24-
doneCallbacks are called with optional arguments `args`.
25+
doneCallbacks are called with optional arguments `args`. The returned
26+
`Timeout` object extends the Deferred's Promise object with the
27+
addional methods `clear()` and `clearWith()`, for rejecting the
28+
Deferred before the delay has elapsed.
2529

2630
### jQuery.timeoutWith( delay, context [, args ] )
2731

2832
Create a Deferred object that will be resolved after the specified
2933
`delay` in milliseconds. When the Deferred is resolved, any
3034
doneCallbacks are called with the given `context` as the `this`
31-
object, and the optional array `args` as arguments.
35+
object, and the optional array `args` as arguments. The returned
36+
`Timeout` object extends the Deferred's Promise object with the
37+
addional methods `clear()` and `clearWith()`, for rejecting the
38+
Deferred before the delay has elapsed.
3239

3340
### timeout.clear( [ args... ] )
3441

35-
Clear a pending timeout by immediately rejecting the corresponding
42+
Clear a pending Promise object returned by `jQuery.timeout()` or
43+
`jQuery.timeoutWith()` by immediately rejecting the corresponding
3644
Deferred object. When the Deferred is rejected, any failCallbacks are
3745
called with optional arguments `args`.
3846

3947
### timeout.clearWith( context [, args ] )
4048

41-
Clear a pending timeout by immediately rejecting the corresponding
49+
Clear a pending Promise object returned by `jQuery.timeout()` or
50+
`jQuery.timeoutWith()` by immediately rejecting the corresponding
4251
Deferred object. When the Deferred is rejected, any failCallbacks are
4352
called with the given `context` as the `this` object, and the optional
4453
array `args` as arguments.
@@ -69,12 +78,10 @@ timeout.
6978

7079
```
7180
var timeout = $.timeout( 10000 );
72-
7381
timeout.then(
7482
function() { alert( "timeout elapsed" ) },
7583
function() { alert( "timeout cleared" ) }
7684
);
77-
7885
$( "#clear" ).click(function() {
7986
timeout.clear();
8087
});

0 commit comments

Comments
 (0)