In the case where multiple Deferred objects are passed to jQuery.when()
, the method returns the Promise from a new "master" Deferred object that tracks the aggregate state of all the Deferreds it has been passed. The method will resolve its master Deferred as soon as all the Deferreds resolve, or reject the master Deferred as soon as one of the Deferreds is rejected. If the master Deferred is resolved, the doneCallbacks for the master Deferred are executed. The arguments passed to the doneCallbacks provide the resolved values for each of the Deferreds, and matches the order the Deferreds were passed to jQuery.when()
. For example:
-var d1 = new $.Deferred();
-var d2 = new $.Deferred();
+var d1 = $.Deferred();
+var d2 = $.Deferred();
$.when( d1, d2 ).done(function ( v1, v2 ) {
console.log( v1 ); // "Fish"
@@ -36,9 +36,9 @@ d2.resolve( "Pizza" );
In the event a Deferred was resolved with no value, the corresponding doneCallback argument will be undefined. If a Deferred resolved to a single value, the corresponding argument will hold that value. In the case where a Deferred resolved to multiple values, the corresponding argument will be an array of those values. For example:
-var d1 = new $.Deferred();
-var d2 = new $.Deferred();
-var d3 = new $.Deferred();
+var d1 = $.Deferred();
+var d2 = $.Deferred();
+var d3 = $.Deferred();
$.when( d1, d2, d3 ).done(function ( v1, v2, v3 ) {
console.log( v1 ); // v1 is undefined