From 90c98cdfa4fb855061324d9276b5b875753a9421 Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Thu, 26 Mar 2015 14:13:22 +0000 Subject: [PATCH] jQuery.when(): remove unnecessary `new` operator Make consistent with other docs. For example: * [`done`](https://github.com/jquery/api.jquery.com/blob/03fcbfbd17b494cc1122b6727adfcd8101b0ea9b/entries/deferred.done.xml#L44) * [`callbacks`](https://github.com/jquery/api.jquery.com/blob/03fcbfbd17b494cc1122b6727adfcd8101b0ea9b/entries/jQuery.Callbacks.xml#L250) --- entries/deferred.promise.xml | 2 +- entries/jQuery.when.xml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/entries/deferred.promise.xml b/entries/deferred.promise.xml index bcd18815..d2a4c12d 100644 --- a/entries/deferred.promise.xml +++ b/entries/deferred.promise.xml @@ -18,7 +18,7 @@ Create a Deferred and set two timer-based functions to either resolve or reject the Deferred after a random interval. Whichever one fires first "wins" and will call one of the callbacks. The second timeout has no effect since the Deferred is already complete (in a resolved or rejected state) from the first timeout action. Also set a timer-based progress notification function, and call a progress handler that adds "working..." to the document body.

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