Promise.prototype
Promise
.prototype
屬性代表了 Promise
建構式的原型物件。
Property attributes of Promise.prototype |
|
---|---|
Writable | no |
Enumerable | no |
Configurable | no |
描述
所有 Promise
實例都繼承自 Promise.prototype
。您可以使用建構式的原型物件來增加屬性或方法到所有的 Promise
實例。
屬性
Promise.prototype.constructor
- 回傳一個建立實例原型(instance's prototype)的函式。預設為
Promise
函數。
方法
Promise.prototype.catch(onRejected)
- 繫結一個拒絕回呼函式(rejection handler callback)到 promise,當它被呼叫時回傳一個以回傳值作解析的新 promise,或者當 promise 被實現時以原值作解析。
Promise.prototype.then(onFulfilled, onRejected)
- 繫結實現或拒絕回呼函式到 promise,回傳一個以 handler 之回傳值作解析的新 promise,或者當 promise 未處理(not handled)時以原值作解析。(i.e. 比如相關聯的
onFulfilled
或onRejected
不是函式。)
規範
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Promise.prototype' in that specification. |
Standard | Initial definition. |
ECMAScript (ECMA-262) The definition of 'Promise.prototype' in that specification. |
Living Standard |
瀏覽器相容性
No compatibility data found for javascript/promise
.
Check for problems with this page or contribute missing data to mdn/browser-compat-data.
To contribute to this compatibility data, please write a pull request against this file: https://github.com/mdn/browser-compat-data/blob/master/javascript/promise.json.