{"id":52970,"date":"2024-12-03T09:04:29","date_gmt":"2024-12-03T01:04:29","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52970\/"},"modified":"2024-12-03T09:04:29","modified_gmt":"2024-12-03T01:04:29","slug":"js%e5%b5%8c%e5%a5%97promise%e4%b8%ad%ef%bc%8c%e5%a6%82%e4%bd%95%e6%ad%a3%e7%a1%ae%e8%8e%b7%e5%8f%96%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%80%bc%e8%80%8c%e4%b8%8d%e6%98%afobject-promise%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52970\/","title":{"rendered":"JS\u5d4c\u5957Promise\u4e2d\uff0c\u5982\u4f55\u6b63\u786e\u83b7\u53d6\u5b57\u7b26\u4e32\u503c\u800c\u4e0d\u662f\\&#8221;[object Promise]\\&#8221;\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>JS\u5d4c\u5957Promise\u4e2d\uff0c\u5982\u4f55\u6b63\u786e\u83b7\u53d6\u5b57\u7b26\u4e32\u503c\u800c\u4e0d\u662f\\&#8221;[object Promise]\\&#8221;\uff1f<\/h1>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u7c73\u4e91\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300aJS\u5d4c\u5957Promise\u4e2d\uff0c\u5982\u4f55\u6b63\u786e\u83b7\u53d6\u5b57\u7b26\u4e32\u503c\u800c\u4e0d\u662f\\&#8221;[object Promise]\\&#8221;\uff1f\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241125\/17325043656743eb2d6cdf2.jpg\" class=\"aligncenter\" title=\"JS\u5d4c\u5957Promise\u4e2d\uff0c\u5982\u4f55\u6b63\u786e\u83b7\u53d6\u5b57\u7b26\u4e32\u503c\u800c\u4e0d\u662f\\&#8221;[object Promise]\\&#8221;\uff1f\u63d2\u56fe\" alt=\"JS\u5d4c\u5957Promise\u4e2d\uff0c\u5982\u4f55\u6b63\u786e\u83b7\u53d6\u5b57\u7b26\u4e32\u503c\u800c\u4e0d\u662f\\&#8221;[object Promise]\\&#8221;\uff1f\u63d2\u56fe\" \/><\/p>\n<p>js \u5d4c\u5957\u7684 promise \u5904\u7406\uff0c\u5982\u4f55\u6b63\u786e\u63d0\u53d6\u5b57\u7b26\u4e32\u503c\uff1f<\/p>\n<p>\u5728 javascript \u4e2d\uff0c\u4f60\u9047\u5230\u4e86\u8fd9\u6837\u7684\u95ee\u9898\uff1a\u4ece promise \u4e2d\u83b7\u53d6\u5b57\u7b26\u4e32\u503c\u65f6\uff0c\u663e\u793a\u7684\u662f &#8220;[object promise]&#8221;\u3002\u8fd9\u662f\u56e0\u4e3a\u4f60\u8fd4\u56de\u7684\u662f\u4e00\u4e2a promise \u5bf9\u8c61\uff0c\u800c\u4e0d\u662f\u5b9e\u9645\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4f60\u5982\u4f55\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li><strong>\u7406\u89e3 promise \u7684\u4f5c\u7528\uff1a<\/strong>promise \u662f javascript \u4e2d\u8868\u793a\u5f02\u6b65\u64cd\u4f5c\u7684\u7ed3\u679c\u5bf9\u8c61\u3002\u5b83\u6709\u4e24\u4e2a\u72b6\u6001\uff1a\u5df2\u89e3\u51b3\uff08\u5177\u6709\u503c\uff09\u6216\u5df2\u62d2\u7edd\uff08\u5177\u6709\u9519\u8bef\uff09\u3002<\/li>\n<li><strong>\u8bc6\u522b\u5f02\u6b65\u51fd\u6570\uff1a<\/strong>\u4f60\u7684 into \u548c intotext \u51fd\u6570\u90fd\u662f\u5f02\u6b65\u51fd\u6570\uff0c\u56e0\u4e3a\u5b83\u4eec\u4f7f\u7528\u4e86 async \u5173\u952e\u5b57\u3002\u8fd9\u4e9b\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a promise\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u8fd4\u56de\u4e00\u4e2a\u503c\u3002<\/li>\n<li><strong>\u5904\u7406 promise\uff1a<\/strong>\u8981\u83b7\u53d6 promise \u7684\u5b9e\u9645\u503c\uff0c\u4f60\u9700\u8981\u4f7f\u7528 .then() \u65b9\u6cd5\u3002\u8be5\u65b9\u6cd5\u63a5\u6536\u4e00\u4e2a\u56de\u8c03\u51fd\u6570\uff0c\u5e76\u5728 promise \u89e3\u51b3\u540e\u8c03\u7528\u8be5\u56de\u8c03\u51fd\u6570\uff0c\u4f20\u9012\u5df2\u89e3\u51b3\u7684\u503c\u3002<\/li>\n<li><strong>\u4f7f\u7528\u56de\u8c03\uff1a<\/strong>\u5728\u4f60\u7684 intotext \u51fd\u6570\u4e2d\uff0c\u4f60\u5e94\u8be5\u4f7f\u7528\u56de\u8c03\u51fd\u6570\u6765\u5904\u7406 into \u51fd\u6570\u8fd4\u56de\u7684 promise\u3002\u5728\u56de\u8c03\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u503c\u4fdd\u5b58\u5230\u4e00\u4e2a\u53d8\u91cf\u6216\u5c06\u5176\u663e\u793a\u51fa\u6765\uff1a<\/li>\n<\/ol>\n<pre>intoText().then((txt) =&gt; {\n  console.log(txt); \/\/ \u73b0\u5728\u4f1a\u663e\u793a\u5b57\u7b26\u4e32\n});<\/pre>\n<p>\u901a\u8fc7\u9075\u5faa\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u4f60\u5c06\u80fd\u591f\u6b63\u786e\u83b7\u53d6\u5e76\u663e\u793a\u4ece promise \u4e2d\u63d0\u53d6\u7684\u5b57\u7b26\u4e32\u503c\u3002<\/p>\n<p>\u672c\u7bc7\u5173\u4e8e\u300aJS\u5d4c\u5957Promise\u4e2d\uff0c\u5982\u4f55\u6b63\u786e\u83b7\u53d6\u5b57\u7b26\u4e32\u503c\u800c\u4e0d\u662f\\&#8221;[object Promise]\\&#8221;\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   win7\u7cfb\u7edf\u4e0d\u80fd\u641c\u7d22\u51fa\u5df2\u6709\u7684\u6587\u4ef6\u600e\u4e48\u89e3\u51b3\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>JS\u5d4c\u5957Promise\u4e2d\uff0c\u5982\u4f55\u6b63\u786e\u83b7\u53d6\u5b57\u7b26\u4e32\u503c\u800c\u4e0d\u662f\\&#8221;[object Promise]\\&#8221;\uff1f \u5bf9\u4e8e\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u7c73\u4e91\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300aJS\u5d4c\u5957Promise\u4e2d\uff0c\u5982\u4f55\u6b63\u786e\u83b7\u53d6\u5b57\u7b26\u4e32\u503c\u800c\u4e0d\u662f\\&#8221;[object Promise]\\&#8221;\uff1f\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01 js \u5d4c\u5957\u7684 promise \u5904\u7406\uff0c\u5982\u4f55\u6b63\u786e\u63d0\u53d6\u5b57\u7b26\u4e32\u503c\uff1f \u5728 javascript \u4e2d\uff0c\u4f60\u9047\u5230\u4e86\u8fd9\u6837\u7684\u95ee\u9898\uff1a\u4ece promise \u4e2d\u83b7\u53d6\u5b57\u7b26\u4e32\u503c\u65f6\uff0c\u663e\u793a\u7684\u662f &#8220;[object promise]&#8221;\u3002\u8fd9\u662f\u56e0\u4e3a\u4f60\u8fd4\u56de\u7684\u662f\u4e00\u4e2a promise \u5bf9\u8c61\uff0c\u800c\u4e0d\u662f\u5b9e\u9645\u7684\u5b57\u7b26\u4e32\u3002 \u4ee5\u4e0b\u662f\u4f60\u5982\u4f55\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\u6b65\u9aa4\uff1a \u7406\u89e3 promise \u7684\u4f5c\u7528\uff1apromise \u662f javascript \u4e2d\u8868\u793a\u5f02\u6b65\u64cd\u4f5c\u7684\u7ed3\u679c\u5bf9\u8c61\u3002\u5b83\u6709\u4e24\u4e2a\u72b6\u6001\uff1a\u5df2\u89e3\u51b3\uff08\u5177\u6709\u503c\uff09\u6216\u5df2\u62d2\u7edd\uff08\u5177\u6709\u9519\u8bef\uff09\u3002 \u8bc6\u522b\u5f02\u6b65\u51fd\u6570\uff1a\u4f60\u7684 into \u548c intotext \u51fd\u6570\u90fd\u662f\u5f02\u6b65\u51fd\u6570\uff0c\u56e0\u4e3a\u5b83\u4eec\u4f7f\u7528\u4e86 async \u5173\u952e\u5b57\u3002\u8fd9\u4e9b\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a promise\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u8fd4\u56de\u4e00\u4e2a\u503c\u3002 \u5904\u7406 promise\uff1a\u8981\u83b7\u53d6 promise \u7684\u5b9e\u9645\u503c\uff0c\u4f60\u9700\u8981\u4f7f\u7528 .then() \u65b9\u6cd5\u3002\u8be5\u65b9\u6cd5\u63a5\u6536\u4e00\u4e2a\u56de\u8c03\u51fd\u6570\uff0c\u5e76\u5728 promise \u89e3\u51b3\u540e\u8c03\u7528\u8be5\u56de\u8c03\u51fd\u6570\uff0c\u4f20\u9012\u5df2\u89e3\u51b3\u7684\u503c\u3002 \u4f7f\u7528\u56de\u8c03\uff1a\u5728\u4f60\u7684 intotext \u51fd\u6570\u4e2d\uff0c\u4f60\u5e94\u8be5\u4f7f\u7528\u56de\u8c03\u51fd\u6570\u6765\u5904\u7406 into \u51fd\u6570\u8fd4\u56de\u7684 promise\u3002\u5728\u56de\u8c03\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u503c\u4fdd\u5b58\u5230\u4e00\u4e2a\u53d8\u91cf\u6216\u5c06\u5176\u663e\u793a\u51fa\u6765\uff1a intoText().then((txt) =&gt; { console.log(txt); \/\/ \u73b0\u5728\u4f1a\u663e\u793a\u5b57\u7b26\u4e32 }); \u901a\u8fc7\u9075\u5faa\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u4f60\u5c06\u80fd\u591f\u6b63\u786e\u83b7\u53d6\u5e76\u663e\u793a\u4ece promise [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-52970","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52970","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=52970"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52970\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}