-
Notifications
You must be signed in to change notification settings - Fork 264
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
Conversation
This is a minimal change to unblock #983. A few other changes to consider separately:
|
pages/Types.html
Outdated
@@ -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 with a <code>then</code> method that returns a <a href="#Promise">Promise</a>-compatible object.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should stick to the definition at https://promisesaplus.com/#point-7 i.e. the only assumption about then
is that it's a function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe mentioning how it relates to promises somehow would clarify things but it should be obvious this is only an advisory remark and not part of the definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've simplified the phrasing, leaving out the Promise mention for now.
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 #906.
@@ -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> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
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 #906.