Skip to content

jQuery.when: Add Thenable and Promise as acceptable types #1026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions entries/jQuery.when.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
<title>jQuery.when()</title>
<signature>
<added>1.5</added>
<argument name="deferreds" type="Deferred">
<desc>Zero or more Deferred objects, or plain JavaScript objects.</desc>
<argument name="deferreds">
<desc>Zero or more Thenable objects.</desc>
<type name="Deferred"/>
<type name="Promise"/>
<type name="Thenable"/>
</argument>
</signature>
<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>
<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>
<longdesc>
<p>If no arguments are passed to <code>jQuery.when()</code>, it will return a resolved Promise.</p>
<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>
Expand Down
3 changes: 3 additions & 0 deletions pages/Types.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<li class="toclevel-1"><a href="#jQuery"><span class="toctext">jQuery</span></a></li>
<li class="toclevel-1"><a href="#XMLHttpRequest"><span class="toctext">XMLHttpRequest</span></a></li>
<li class="toclevel-1"><a href="#jqXHR"><span class="toctext">jqXHR</span></a></li>
<li class="toclevel-1"><a href="#Thenable"><span class="toctext">Thenable</span></a></li>
<li class="toclevel-1"><a href="#Deferred"><span class="toctext">Deferred Object</span></a></li>
<li class="toclevel-1"><a href="#Promise"><span class="toctext">Promise Object</span></a></li>
<li class="toclevel-1"><a href="#Callbacks"><span class="toctext">Callbacks Object</span></a></li>
Expand Down Expand Up @@ -657,6 +658,8 @@ <h2 id="XMLHttpRequest"> XMLHttpRequest </h2>
<h2 id="jqXHR"> jqXHR </h2>
<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>
</p>
<h2 id="Thenable">Thenable</h2>
<p>Any object that has a <code>then</code> method.</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the spec at https://promisesaplus.com/#point-7 mentions functions with a then method as acceptable input as well.

That's a little weird one but technically we're still accepting those so maybe we should keep our definition identical to the Promises/A+ one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mgol I considered that but found it more confusing than useful. All functions are objects. So this isn't contradictory.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, OK. I guess it was mentioned as that's the only object that has a non-"object" typeof.

<h2 id="Deferred"> Deferred Object</h2>
<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.
</p>
Expand Down