I can find some blog posts stating that JavaScript ES6's promise is Promise/A+, but the official ES6 specs doesn't mention it, and MDN has a link to Promise/A+ at the very bottom, but didn't state that ES6 JavaScript's promise is exactly the same as Promise/A+.
Sometimes it is stated as "ES6 promise is based on Promise/A+", but are they exactly the same? ( is it mentioned in official docs, such as from ECMA or MDN?)
They aren't identical, but JavaScript's promises are fully compliant with the Promises/A+ specification.
Promises/A+ is intentionally minimalist. JavaScript's promises have utility features that aren't covered by the Promises/A+ spec (such as catch
and finally
). Those are implemented using only features covered by Promises/A+, though. For instance, catch
and finally
are implemented via calls to then
. (Literally, not just conceptually.) If you look at the specification for catch
for example, it says catch
is literally this:
class Promise {
// ...
catch(onRejected) {
return this.then(undefined, onRejected);
}
// ...
}
(finally
is a bit more complex, but it too ends up calling then
and returning the promise it creates.)
JavaScript's promises also have the occasional optimization that only works if a native promise (instead of a promise from a third-party library) is used, but again, they're fully compliant with Promises/A+.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With