jQuery.when: Add Thenable and Promise as acceptable types#1026
Conversation
|
This is a minimal change to unblock #983. A few other changes to consider separately:
|
| <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.
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.
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.
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.
| <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.
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.
@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.
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.