From e975b119c96114af3dd93b886aca93dbbb8f944e Mon Sep 17 00:00:00 2001 From: snowingfox <1503401882@qq.com> Date: Fri, 12 Nov 2021 09:24:33 +0800 Subject: 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 --- .../reference/global_objects/promise/resolve/index.html | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'files/zh-cn/web/javascript/reference/global_objects') 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

警告:不要在解析为自身的thenable 上调用Promise.resolve。这将导致无限递归,因为它试图展平无限嵌套的promise。一个例子是将它与Angular中的异步管道一起使用。在此处了解更多信息。

+
例如下例代码
+
+let thenable = {
+  then: (resolve, reject) => {
+    resolve(thenable)
+  }
+}
+
+Promise.resolve(thenable)  //这会造成一个死循环
+
{{EmbedInteractiveExample("pages/js/promise-resolve.html")}}
-- cgit v1.2.3-54-g00ecf