PromiseRejectionEvent
PromiseRejectionEvent
接口表示出现在 JavaScript Promise
s 被 rejecte (拒绝) 时触发的事件。这些事件对遥测 (远程测试) 和调试特别的有用。
构造函数
PromiseRejectionEvent()
-
用给定的参数生成一个
PromiseRejectionEvent
事件。
属性
也从它的父级Event
继承属性。
PromiseRejectionEvent.promise
只读-
被 rejected 的 JavaScript
Promise
。 PromiseRejectionEvent.reason
只读-
一个值或
Object
表明为什么 promise 被 rejected,并传递给Promise.reject()
。
方法
没有特定的方法; 从它的父级 Event
继承方法。
事件
rejectionhandled
-
在一个 JavaScript
Promise
被 reject 时触发,在 reject 后由 promise 的 reject 处理函数处理。 unhandledrejection
-
在一个 JavaScript
Promise
被 reject(拒绝)但是没有 reject 处理函数来处理时触发。
示例
js
window.onunhandledrejection = function (e) {
console.log(e.reason);
};
规范
Specification |
---|
HTML # the-promiserejectionevent-interface |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PromiseRejectionEvent | |||||||||||||
PromiseRejectionEvent() constructor | |||||||||||||
promise | |||||||||||||
reason |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.