The jQuery._Deferred is an object maintaining a task list. To understanding it, help you to understand how the jQuery.Deferred and jQuery.when works. The _Deferred object has the following use case.

  • Push your task into the list to be run(resolved) in the future. It has been resolved, call the resolved method again.

  • Resolve(run) the tasks in the list, the task will be run in the order you push it, [].shift method is used to dequeue from the list. If everything runs fine, the task will be empty.

  • Push the task into task list during the task is run. But the new task will the last one to run.

  • Exception handling inside of your task. If the current task is run synchronously, you can optionally use exception handling, an exception is not caught, the remaining tasks will be canceled.

  • You have an option to eagerly cancel the remaining task, in the current running task. This is an advanced task.

  • Once you resolve the task list one a set of values, then the resolve context, and values are cached. If you resolve it again with new values, the new task still be run, but run in the old context, and values.