$.Deferred() (same as jQuery.Deferred()) is a factory that returns a new Deferred object (since jQuery 1.5). Officially it creates a chainable utility for registering callbacks, invoking them, and relaying success or failure of sync or async work — the same pattern used by $.ajax().
Syntax
Start with these common calls. Keep them short and readable.
Protect. Outside code cannot call resolve early by accident.
Frequently Asked Questions
$.Deferred() (same as jQuery.Deferred()) is a factory that creates a new Deferred object — a chainable handle for one async operation you control with resolve(), reject(), and callback methods like done() and fail().
A Deferred can resolve or reject itself. deferred.promise() returns a read-only Promise that exposes done/fail/then but hides resolve/reject — return that when sharing async work with other code.
pending (not finished), resolved (success), or rejected (failure). After resolve or reject, the state is locked; further settle calls are ignored.
Yes. An optional beforeStart function runs just before the factory returns, with the new Deferred as this and as the first argument. Use it to attach early callbacks or start async setup.
jqXHR from $.ajax() implements the Deferred interface. $.Deferred() lets you build the same callback patterns for your own timers, validators, and helpers.
Deferred objects were added in jQuery 1.5 and remain available in modern 1.x, 2.x, and 3.x builds.