Deferred objects
In jQuery 1.5, a concept known as a deferred object was introduced to the library. A deferred object encapsulates an operation that takes some time to complete. These objects allow us to easily handle situations in which we want to act when a process completes, but we don't necessarily know how long the process will take or even if it will be successful.
A new deferred object can be created at any time by calling the $.Deferred()
constructor. Once we have such an object, we can perform long-lasting operations and then call the .resolve()
or .reject()
methods on the object to indicate the operation was successful or unsuccessful. It is somewhat unusual to do this manually, however. Typically, rather than creating our own deferred objects by hand, jQuery or its plugins will create the object and take care of resolving or rejecting it. We just need to learn how to use the object that is created.
Note
Creating deferred objects is a very advanced topic—more advanced than is appropriate...