Discussion:
Promise.resolve() and jQuery deferreds
Axel Rauschmayer
2014-10-03 13:21:03 UTC
Permalink
AFAICT, `Promise.resolve()` is enough to convert jQuery deferreds to the ES6 API. Correct?

Thanks!

Axel
--
Dr. Axel Rauschmayer
axel at rauschma.de
rauschma.de



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20141003/59b158c2/attachment.html>
C. Scott Ananian
2014-10-03 15:07:50 UTC
Permalink
Post by Axel Rauschmayer
AFAICT, `Promise.resolve()` is enough to convert jQuery deferreds to the ES6 API. Correct?
AFAIK `Promise.resolve()` should be enough to turn any thenable into a promise.

And when you subclass, `SubPromise.resolve(p)` should be enough to
turn any thenable or promise of a different subclass into your
subclass.

I have considered rewriting my `prfun` library of Promise utilities so
that it creates a subclass of Promise rather than adding methods to
the global prototype. This would require `var Promise =
require('prfun')` would return the subclass, and you'd need to do
`Promise.resolve(p)` whenever you got a promise (or thenable) from
"outside" your API in order to ensure that the result had the `prfun`
methods.

(If I'm misunderstanding `Promise.resolve`, let me know!)
--scott

Loading...