Promise.prototype

Promise.prototype

Promise.prototype 属性表示Promise构造器的原型.

| Promise.prototype属性的属性特性 |

|:----|

| Writable | no |

| Enumerable | no |

| Configurable | no |

描述

Promise实例继承自 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.

规范

SpecificationStatusComment
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Promise.prototype' in that specification.StandardInitial definition.
ECMAScript Latest Draft (ECMA-262)The definition of 'Promise.prototype' in that specification.Living Standard

浏览器兼容性

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic Support32.0(Yes)29.0No197.1

FeatureAndroidChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic Support4.4.432.0(Yes)29No(Yes)8.0