PromiseRejectionEvent.promise

这篇翻译不完整。请帮忙从英语翻译这篇文章

 PromiseRejectionEvent事件对象的promise属性是只读的,表明Promise被reject的原因。您可以通过检查PromiseRejectionEvent.reason来了解Promise为什么被reject。

Syntax

promise = PromiseRejectionEvent.promise

Value

一个被reject的,并且错误未被处理的Promise 

Examples

下面的例子监听了未被处理的promise,如果reason 是一个对象,并且其code属性包含了一段文本“Module not read.”,一个空闲的回调函数被声明,当任务执行错误时会进行重试

event.preventDefault() 用来表明该promise已被处理

window.onunhandledrejection = function(event) {
  if (event.reason.code && event.reason.code == "Module not ready") {
    window.requestIdleCallback(function(deadline) {
      loadModule(event.reason.moduleName)
        .then(performStartup);
    });
    event.preventDefault();
  }
}

Specifications

Specification Status Comment
HTML Living Standard
PromiseRejectionEvent.promise
Living Standard Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
promiseChrome Full support 49Edge ? Firefox Full support 69
Full support 69
Full support 68
Disabled
Disabled From version 68: this feature is behind the dom.promise_rejection_events.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE No support NoOpera Full support 36Safari Full support 11WebView Android Full support 49Chrome Android Full support 49Firefox Android Full support 68
Disabled
Full support 68
Disabled
Disabled From version 68: this feature is behind the dom.promise_rejection_events.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera Android Full support 36Safari iOS Full support 11.3Samsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
User must explicitly enable this feature.
User must explicitly enable this feature.

See also

文档标签和贡献者

此页面的贡献者: mdnwebdocs-bot, duola8789
最后编辑者: mdnwebdocs-bot,