From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../api/promiserejectionevent/promise/index.html | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 files/zh-cn/web/api/promiserejectionevent/promise/index.html (limited to 'files/zh-cn/web/api/promiserejectionevent/promise/index.html') diff --git a/files/zh-cn/web/api/promiserejectionevent/promise/index.html b/files/zh-cn/web/api/promiserejectionevent/promise/index.html new file mode 100644 index 0000000000..d539826ce8 --- /dev/null +++ b/files/zh-cn/web/api/promiserejectionevent/promise/index.html @@ -0,0 +1,66 @@ +--- +title: PromiseRejectionEvent.promise +slug: Web/API/PromiseRejectionEvent/promise +translation_of: Web/API/PromiseRejectionEvent/promise +--- +
{{APIRef("HTML DOM") }}
+ +

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

+ +

Syntax

+ +
promise = PromiseRejectionEvent.promise
+ +

Value

+ +

一个被reject的,并且错误未被处理的{{jsxref("Promise")}} 

+ +

Examples

+ +

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

+ +

{{domxref("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

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', 'webappapis.html#dom-promiserejectionevent-promise', 'PromiseRejectionEvent.promise')}}{{ Spec2('HTML WHATWG') }}Initial definition.
+ +

浏览器兼容性

+ + + +

{{Compat("api.PromiseRejectionEvent.promise")}}

+ +

See also

+ + -- cgit v1.2.3-54-g00ecf