diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
| commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
| tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/promiserejectionevent/index.html | |
| parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
| download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip | |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/promiserejectionevent/index.html')
| -rw-r--r-- | files/zh-cn/web/api/promiserejectionevent/index.html | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/promiserejectionevent/index.html b/files/zh-cn/web/api/promiserejectionevent/index.html new file mode 100644 index 0000000000..997aa87b43 --- /dev/null +++ b/files/zh-cn/web/api/promiserejectionevent/index.html @@ -0,0 +1,124 @@ +--- +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> + +<p>{{CompatibilityTable}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>功能</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>基本支持</td> + <td>49</td> + <td>{{CompatNo}}<sup>[1]</sup></td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>功能</th> + <th>Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>基本支持</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}<sup>[1]</sup></td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<p>[1] 在 Firefox 里,有实现这个接口但是默认是禁用的。要打开它的话,去到about:config 将 <code>dom.promise_rejection_events.enabled 启用为真。</code></p> + +<h2 id="参见">参见</h2> + +<ul> + <li>{{jsxref("Promise")}}</li> + <li>{{domxref("WindowEventHandlers.onrejectionhandled")}}</li> + <li>{{domxref("WindowEventHandlers.onunhandledrejection")}}</li> +</ul> |
