总结
Promise
.prototype
属性表示 Promise
构造器的原型.
Promise.prototype 属性的属性特性: |
|
---|---|
writable | false |
enumerable | false |
configurable | false |
描述
Promise.prototype
. 你可以在构造器的原型对象添加属性或方法到所有 Promise
实例上.
属性
-
Promise.prototype.constructor
-
返回被创建的实例函数. 默认为
Promise
函数.
方法
-
Promise.prototype.catch(onRejected)
- 添加一个拒绝(rejection) 回调到当前 promise, 返回一个新的promise。当这个回调函数被调用,新 promise 将以它的返回值来resolve,否则如果当前promise 进入fulfilled状态,则以当前promise的完成结果作为新promise的完成结果.
-
Promise.prototype.then(onFulfilled, onRejected)
- 添加解决(fulfillment)和拒绝(rejection)回调到当前 promise, 返回一个新的 promise, 将以回调的返回值来resolve.
-
Promise.prototype.finally(onFinally)
- 添加一个事件处理回调于当前promise对象,并且在原promise对象解析完毕后,返回一个新的promise对象。回调会在当前promise运行完毕后被调用,无论当前promise的状态是完成(fulfilled)还是失败(rejected)
规范
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) Promise.prototype |
Standard | Initial definition. |
浏览器兼容
We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 32 | 24.0 (24.0) as Future 25.0 (25.0) as Promise behind a flag[1]29.0 (29.0) by default |
未实现 | 19 | 7.1 |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|
Basic support | 未实现 | 24.0 (24.0) as Future 25.0 (25.0) as Promise behind a flag[1]29.0 (29.0) by default |
未实现 | 未实现 | iOS 8 | 32 |
[1] Gecko 24 has an experimental implementation of Promise
, under the initial name of Future
. It got renamed to its final name in Gecko 25, but disabled by default behind the flag dom.promise.enabled
. Bug 918806 enabled Promises by default in Gecko 29.