YouTip LogoYouTip

Misc Jquery Deferred

# jQuery jQuery.Deferred() Method [![Image 3: jQuery Miscellaneous Methods](#)jQuery Miscellaneous Methods](#) * * * ## Definition and Usage $.Deferred() is a constructor that returns a chainable utility object method for registering multiple callbacks and invoking callback queues, passing the success or failure status 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 passes a new Deferred object as the first argument to the function. For example, the called function can use deferred.then() to attach callback functions. 2. A Deferred object starts in a pending state. Any callback functions added to this 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 a resolved or rejected Deferred objectβ€”they will execute immediately. * * * ## Syntax _$_.Deferred( ) | Parameter | Description | | :--- | :--- | | _beforeStart_ | Function( Deferred deferred )Type A function that is called before the constructor returns | * * jQuery Miscellaneous Methods](#)
← Misc Deferred IsrejectedMisc Callbacks Has β†’