jQuery jQuery.Deferred()Method
Definition and Usage
$.Deferred() is a constructor function used to return a chainable utility object method for registering multiple callbacks and calling the callback queue, passing the success or failure state of any synchronous or asynchronous function.
Tip:1. The $.Deferred() constructor creates a new Deferred object. jQuery.Deferred can accept an optional function that is called before the constructor returns and is passed the new Deferred object as the first argument of the function. For example, the called function can use deferred.then() to attach callback functions.
2. A Deferred object starts in the pending state. Any callback functions added to this object using deferred.then(), deferred.always(), deferred.done(), or deferred.fail() are queued and wait to be executed. Calling deferred.resolve() or deferred.resolveWith() transitions the deferred to the resolved state and immediately executes the set doneCallbacks. Calling deferred.reject() or deferred.rejectWith() transitions the deferred to the rejected state and immediately executes the set failCallbacks. Once the object has entered the resolved or rejected state, it remains in that state. Callbacks can still be added to a resolved or rejected Deferred object - they will execute immediately.
Syntax
| Parameter | Description |
|---|---|
| beforeStart | Function( Deferred deferred ) type: A function called before the constructor returns. |
Other Extensions
jQuery Miscellaneous Methods