3 ms·
You need to do this test if you are creating a promise implementation. That was my point, there is a reason code like this exists.
by city41 7y ago
You need to do this test if you are creating a promise implementation. That was my point, there is a reason code like this exists.
- earthboundkid 7y agoWhy would an implementation need to test for it? ISTM that a framework may need to test for promiseness if it calls promises and functions differently, but it can and should be done as a utility in the framework, not as a separate package.
- city41 7y agoI agree with that. I have no idea why it’s in a separate package. But I can say that about many packages :). It’s possible to just treat everything as a promise by wrapping results in Promise.resolve() but that can have performance implications that some franeworks might want to avoid by only going down the promise route when they have to. For promise implementations, If the callback to then() returns a promise, the promise implementation detects that and resolves that promise behind the scenes: http://www.mattgreer.org/articles/promises-in-wicked-detail/#returning-promises-inside-the-chain http://www.mattgreer.org/articles/promises-in-wicked-detail/...