diff options
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects')
-rw-r--r-- | files/zh-cn/web/javascript/reference/global_objects/promise/resolve/index.html | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/promise/resolve/index.html b/files/zh-cn/web/javascript/reference/global_objects/promise/resolve/index.html index 7e92b06d1a..6ca8158da1 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/promise/resolve/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/promise/resolve/index.html @@ -18,6 +18,16 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Promise/resolve <div class="blockIndicator warning"> <p>警告:不要在解析为自身的thenable 上调用<code>Promise.resolve</code>。这将导致无限递归,因为它试图展平无限嵌套的promise。一个例子是将它与Angular中的异步管道一起使用。在<a href="https://angular.io/guide/template-syntax#avoid-side-effects">此处</a>了解更多信息。</p> </div> +<div>例如下例代码</div> +<pre class="brush: js"> +let thenable = { + then: (resolve, reject) => { + resolve(thenable) + } +} + +Promise.resolve(thenable) //这会造成一个死循环 +</pre> <div>{{EmbedInteractiveExample("pages/js/promise-resolve.html")}}</div> |