blob: 7c9d0e127a8601debd2f48856c532eeb967db2c2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
---
title: PromiseRejectionEvent
slug: Web/API/PromiseRejectionEvent
translation_of: Web/API/PromiseRejectionEvent
---
<div>{{APIRef("HTML DOM")}}</div>
<p><strong><code>PromiseRejectionEvent</code></strong> 接口表示出现在JavaScript {{jsxref("Promise")}}s 被rejecte (拒绝) 时触发的事件。这些事件对遥测(远程测试)和调试特别的有用。</p>
<h2 id="构造函数">构造函数</h2>
<dl>
<dt>{{domxref("PromiseRejectionEvent.PromiseRejectionEvent", "PromiseRejectionEvent()")}}</dt>
<dd>用给定的参数生成一个 <code>PromiseRejectionEvent</code> 事件。</dd>
</dl>
<h2 id="属性">属性</h2>
<p><em>也从它的父级{{domxref("Event")}}继承属性。</em></p>
<dl>
<dt>{{domxref("PromiseRejectionEvent.promise")}} {{readOnlyInline}}</dt>
<dd>被 rejected 的 JavaScript {{jsxref("Promise")}} 。</dd>
<dt>{{domxref("PromiseRejectionEvent.reason")}} {{readOnlyInline}}</dt>
<dd>一个值或 {{jsxref("Object")}} 表明为什么 promise 被 rejected,并传递给{{jsxref("Promise.reject()")}}。</dd>
</dl>
<h2 id="方法">方法</h2>
<p><em>没有特定的方法; 从它的父级 {{domxref("Event")}}继承方法。</em></p>
<h2 id="事件">事件</h2>
<dl>
<dt>{{Event("unhandledrejection")}}</dt>
<dd>在一个JavaScript {{jsxref("Promise")}} 被 reject(拒绝) 但是没有 reject 处理函数来处理时触发。</dd>
<dt>{{Event("rejectionhandled")}}</dt>
<dd>在一个JavaScript {{jsxref("Promise")}} 被 reject 时触发,在 reject 后由promise的 reject 处理函数处理。 </dd>
</dl>
<h2 id="例子">例子</h2>
<pre class="brush: js">window.onunhandledrejection = function(e) {
console.log(e.reason);
}</pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('HTML WHATWG', 'webappapis.html#promiserejectionevent', 'PromiseRejectionEvent')}}</td>
<td>{{ Spec2('HTML WHATWG') }}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
{{Compat("api.PromiseRejectionEvent")}}
<h2 id="参见">参见</h2>
<ul>
<li>{{jsxref("Promise")}}</li>
<li>{{domxref("WindowEventHandlers.onrejectionhandled")}}</li>
<li>{{domxref("WindowEventHandlers.onunhandledrejection")}}</li>
</ul>
|