Skip to content

Commit 3ab6720

Browse files
Krinklemgol
authored andcommitted
jQuery.when: Add Thenable and Promise as acceptable types
Technically replacing Deferred with Thenable would work, but mentioning Deferred and Promise directly should make this easier to understand for new and existing users. Fixes jquery#906 Closes jquery#1026
1 parent b2b9d8a commit 3ab6720

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

entries/jQuery.when.xml

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
<title>jQuery.when()</title>
44
<signature>
55
<added>1.5</added>
6-
<argument name="deferreds" type="Deferred">
7-
<desc>Zero or more Deferred objects, or plain JavaScript objects.</desc>
6+
<argument name="deferreds">
7+
<desc>Zero or more Thenable objects.</desc>
8+
<type name="Deferred"/>
9+
<type name="Promise"/>
10+
<type name="Thenable"/>
811
</argument>
912
</signature>
10-
<desc>Provides a way to execute callback functions based on zero or more objects, usually <a href="/category/deferred-object/">Deferred</a> objects that represent asynchronous events.</desc>
13+
<desc>Provides a way to execute callback functions based on zero or more Thenable objects, usually <a href="/category/deferred-object/">Deferred</a> objects that represent asynchronous events.</desc>
1114
<longdesc>
1215
<p>If no arguments are passed to <code>jQuery.when()</code>, it will return a resolved Promise.</p>
1316
<p>If a single Deferred is passed to <code>jQuery.when()</code>, its Promise object (a subset of the Deferred methods) is returned by the method. Additional methods of the Promise object can be called to attach callbacks, such as <a href="/deferred.then/"><code>deferred.then</code></a>. When the Deferred is resolved or rejected, usually by the code that created the Deferred originally, the appropriate callbacks will be called. For example, the jqXHR object returned by <code>jQuery.ajax()</code> is a Promise-compatible object and can be used this way:</p>

pages/Types.html

+3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<li class="toclevel-1"><a href="#jQuery"><span class="toctext">jQuery</span></a></li>
9494
<li class="toclevel-1"><a href="#XMLHttpRequest"><span class="toctext">XMLHttpRequest</span></a></li>
9595
<li class="toclevel-1"><a href="#jqXHR"><span class="toctext">jqXHR</span></a></li>
96+
<li class="toclevel-1"><a href="#Thenable"><span class="toctext">Thenable</span></a></li>
9697
<li class="toclevel-1"><a href="#Deferred"><span class="toctext">Deferred Object</span></a></li>
9798
<li class="toclevel-1"><a href="#Promise"><span class="toctext">Promise Object</span></a></li>
9899
<li class="toclevel-1"><a href="#Callbacks"><span class="toctext">Callbacks Object</span></a></li>
@@ -657,6 +658,8 @@ <h2 id="XMLHttpRequest"> XMLHttpRequest </h2>
657658
<h2 id="jqXHR"> jqXHR </h2>
658659
<p>As of jQuery 1.5, the <a href="/jQuery.ajax/">$.ajax()</a> method returns the jqXHR object, which is a superset of the XMLHTTPRequest object. For more information, see the <a href="/jQuery.ajax/#jqXHR">jqXHR section of the $.ajax entry</a>
659660
</p>
661+
<h2 id="Thenable">Thenable</h2>
662+
<p>Any object that has a <code>then</code> method.</p>
660663
<h2 id="Deferred"> Deferred Object</h2>
661664
<p>As of jQuery 1.5, the <a href="/category/deferred-object/">Deferred</a> object provides a way to register multiple callbacks into self-managed callback queues, invoke callback queues as appropriate, and relay the success or failure state of any synchronous or asynchronous function.
662665
</p>

0 commit comments

Comments
 (0)