aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/promise/reject/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/promise/reject/index.html')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/promise/reject/index.html78
1 files changed, 78 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/promise/reject/index.html b/files/zh-cn/web/javascript/reference/global_objects/promise/reject/index.html
new file mode 100644
index 0000000000..f5a8f82156
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/global_objects/promise/reject/index.html
@@ -0,0 +1,78 @@
+---
+title: Promise.reject()
+slug: Web/JavaScript/Reference/Global_Objects/Promise/reject
+tags:
+ - ECAMScript 2015
+ - JavaScript
+ - Method
+ - Promise
+translation_of: Web/JavaScript/Reference/Global_Objects/Promise/reject
+---
+<div>{{JSRef}}</div>
+
+<p><code><strong>Promise.reject()</strong></code>方法返回一个带有拒绝原因的<code>Promise</code>对象。</p>
+
+<p>{{EmbedInteractiveExample("pages/js/promise-reject.html")}}</p>
+
+<h2 id="Syntax" name="Syntax">语法</h2>
+
+<pre class="syntaxbox"><var>Promise.reject(reason)</var>;</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt>reason</dt>
+ <dd>表示<code>Promise</code>被拒绝的原因。</dd>
+</dl>
+
+<h3 id="返回值">返回值</h3>
+
+<dl>
+ <dd>一个给定原因了的被拒绝的 {{jsxref("Promise")}}。</dd>
+</dl>
+
+<h2 id="Description" name="Description">描述</h2>
+
+<p><font face="Open Sans, sans-serif">静态函数</font><code>Promise.reject</code>返回一个被拒绝的<code>Promise对象</code>。通过使用{{jsxref("Error")}}的实例获取错误原因<code>reason</code>对调试和选择性错误捕捉很有帮助。</p>
+
+<h2 id="示例">示例</h2>
+
+<h3 id="使用静态Promise.reject方法">使用静态<code>Promise.reject()</code>方法</h3>
+
+<pre><code>Promise.reject(new Error('fail')).then(function() {
+ // not called
+}, function(error) {
+ console.error(error); // Stacktrace
+});</code></pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">规范</th>
+ <th scope="col">状态</th>
+ <th scope="col">备注</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES2015', '#sec-promise.reject', 'Promise.reject')}}</td>
+ <td>{{Spec2('ES2015')}}</td>
+ <td>ECMA规范的首次定义</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-promise.reject', 'Promise.reject')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<p>{{Compat("javascript.builtins.Promise.reject")}}</p>
+
+<h2 id="参见">参见</h2>
+
+<ul>
+ <li>{{jsxref("Promise")}}</li>
+</ul>