aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web
diff options
context:
space:
mode:
authorsnowingfox <1503401882@qq.com>2021-11-12 09:24:33 +0800
committerGitHub <noreply@github.com>2021-11-12 09:24:33 +0800
commite975b119c96114af3dd93b886aca93dbbb8f944e (patch)
tree1e9ac0b82b21a41d93104dc9b2e19d63ae29a838 /files/zh-cn/web
parentdaa80a45b41e91e2621c41f36f18a01861598332 (diff)
downloadtranslated-content-e975b119c96114af3dd93b886aca93dbbb8f944e.tar.gz
translated-content-e975b119c96114af3dd93b886aca93dbbb8f944e.tar.bz2
translated-content-e975b119c96114af3dd93b886aca93dbbb8f944e.zip
Update Web/JavaScript/Reference/Global_Objects/Promise/resolve, zh-CN (#2967)
A code example is added to the warning content at the beginning of the article. This example can clearly show its meaning. Why should I give this example? Because when I first read it, I found it difficult to imagine and understand this concept
Diffstat (limited to 'files/zh-cn/web')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/promise/resolve/index.html10
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>