promises3 v0.1.0
PromisEs3
Introduction
PromisEs3 is a implementation of Promise/A+ for ES3. Its single-file and dependence-free features are designed for maximum compatibility, which is important when buiding/packing/moduling tools are not available or old browsers (like IE6) need to be considered.
This Promise
implemented by this project have passed the Promise/A+ test.
Although the basic part are written in pure ES3 syntax and functions, it can make use of some ES3+ or non-standard function to obtain additional performance.
Usage
Include by <script>
Tag
You can
Directly include the Promise.js file (relatively large-sized).
Include the compressed file promises3.min.js. Can be downloaded from Release.
When included by <script>
tag, it will act as an polyfill, which means that create the Promise
class in the global scope when it dosen't exist.
As Module
When PromisEs3 are imported as a module, it directly exports the the Promise
class.
Can be used as:
As Node.js (+ CommonJS) + npm module
- Download by npm as promises3 package.
- Include as module
promises3
(require("promises3")
).
AMD module.
CMD module.
Known Issue
As most of the Promise implementation, the
Promise.prototype.toString
are directly inherited fromObject.prototype.toString
and not have been overwritten. Only whenSymbol.toStringTag
is available, the result ofpromise.toString()
andObject.prototype.toString.call(promise)
is guaranteed to be"[object Promise]"
.When the iterable protocol is not available,
Promise.all
,Promise.allSettled
an other static functions takesArrayLike
asIterable
.On the branch with-any, a static function
Promise.any
is implemented. An Exception class calledAggregateError
which is needed byPromise.any
is also implemented and exported. However, they cannot be fully polyfilled under ES5. As these 2 features are still in working draft (see MDN) and not be included in any main-stream browsers, using it is strongly deprecated.
Notice
Some properties of the
Promise
object has keys embraced by"[[]]"
. These properties should be seen as private properties and should not be modified externally.In some ES3 browsers, if a object member's key is a JavaScript keyword, accessing it by operator
.
is not allowed. You can usepromise["catch"]
andpromise["finally"]
instead ofpromise.catch
andpromise.finally
. Some tools, like babel/plugin-transform-member-expression-literals may help you covert these codes automatically.
License and Copyright
MIT Licence. See LICENSE.md.
Copyright (c) 2020 Yichen Liu.