Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery jQuery.Deferred() method

jQuery jQuery.Deferred() method

jQuery Miscellaneous MethodsjQuery Miscellaneous Methods


Definition and Usage

$.Deferred() is a constructor that returns a chainable utility object with methods to register multiple callbacks, invoke callback queues, and transmit the success or failure state of any synchronous or asynchronous function.

**Tip:** 1. The $.Deferred() constructor creates a new Deferred object. jQuery.Deferred can be passed an optional function that is called before the constructor returns and is passed a new Deferred object as its first argument. For example, the called function can use deferred.then() to attach callbacks.
2. A Deferred object begins in the pending state. Any callbacks added to the object using deferred.then(), deferred.always(), deferred.done(), or deferred.fail() are queued for execution. 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 an already resolved or rejected Deferred object--they are executed immediately.


Syntax

$

.Deferred( [beforeStart ] )

Parameters Description
beforeStart Function( Deferred deferred ) type: A function called before the constructor returns

jQuery Miscellaneous MethodsjQuery Miscellaneous Methods