{"id":10021081,"date":"2025-11-18T14:07:11","date_gmt":"2025-11-18T06:07:11","guid":{"rendered":"https:\/\/itmax.cn\/?p=10021081"},"modified":"2025-11-18T14:07:11","modified_gmt":"2025-11-18T06:07:11","slug":"javascript-promise-%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10021081","title":{"rendered":"JavaScript Promise \u8be6\u89e3"},"content":{"rendered":"<h2>JavaScript Promise \u5b8c\u5168\u6307\u5357\uff1a\u4ece\u57fa\u7840\u5230\u8fdb\u9636<\/h2>\n<h3>\u4e00\u3001Promise \u6784\u9020\u51fd\u6570\u57fa\u7840<\/h3>\n<h4>1.1 \u57fa\u672c\u8bed\u6cd5\u7ed3\u6784<\/h4>\n<pre><code class=\"javascript\">var my_promise = new Promise(function(resolve, reject) {\n    \/\/ \u6267\u884c\u5668\u51fd\u6570\n    if (\u6761\u4ef6) {\n        resolve('\u6210\u529f\u503c');\n    } else {\n        reject('\u5931\u8d25\u503c');\n    }\n});<\/code><\/pre>\n<h4>1.2 \u6267\u884c\u5668\u51fd\u6570\uff08Executor Function\uff09<\/h4>\n<ul>\n<li><code>function(resolve, reject)<\/code> \u662f<strong>\u533f\u540d\u51fd\u6570<\/strong>\uff0c\u4e5f\u79f0\u4e3a<strong>\u6267\u884c\u5668\u51fd\u6570<\/strong><\/li>\n<li>\u8be5\u51fd\u6570\u6709\u4e24\u4e2a\u53c2\u6570\uff1a<code>resolve<\/code> \u548c <code>reject<\/code><\/li>\n<li>\u26a1 <strong>\u5173\u952e\u7279\u6027<\/strong>\uff1a\u6267\u884c\u5668\u51fd\u6570\u5728 <code>new Promise()<\/code> \u65f6<strong>\u7acb\u5373\u540c\u6b65\u6267\u884c<\/strong><\/li>\n<\/ul>\n<h4>1.3 resolve \u548c reject \u53c2\u6570\u8be6\u89e3<\/h4>\n<ul>\n<li><strong>\u672c\u8d28<\/strong>\uff1a<code>resolve<\/code> \u548c <code>reject<\/code> \u662f<strong>\u51fd\u6570\u53c2\u6570<\/strong>\uff08\u4e0d\u662f\u5c5e\u6027\u6216\u65b9\u6cd5\uff09<\/li>\n<li><strong>\u6765\u6e90<\/strong>\uff1a\u7531 JavaScript \u5f15\u64ce\u81ea\u52a8\u521b\u5efa\u5e76\u4f20\u9012\u7ed9\u6267\u884c\u5668\u51fd\u6570<\/li>\n<li>\n<p><strong>\u4f5c\u7528<\/strong>\uff1a<\/p>\n<ul>\n<li><code>resolve(value)<\/code>\uff1a\u5c06 Promise \u72b6\u6001\u6539\u4e3a <code>fulfilled<\/code>\uff0c\u5e76\u4f20\u9012\u6210\u529f\u503c<\/li>\n<li><code>reject(reason)<\/code>\uff1a\u5c06 Promise \u72b6\u6001\u6539\u4e3a <code>rejected<\/code>\uff0c\u5e76\u4f20\u9012\u5931\u8d25\u539f\u56e0<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr>\n<h3>\u4e8c\u3001Promise \u7684\u4e09\u79cd\u72b6\u6001<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u72b6\u6001<\/th>\n<th>\u82f1\u6587\u540d<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u7b49\u5f85\u4e2d<\/td>\n<td><code>pending<\/code><\/td>\n<td>Promise \u7684\u521d\u59cb\u72b6\u6001<\/td>\n<\/tr>\n<tr>\n<td>\u5df2\u6210\u529f<\/td>\n<td><code>fulfilled<\/code><\/td>\n<td>\u8c03\u7528 <code>resolve()<\/code> \u540e\u7684\u72b6\u6001<\/td>\n<\/tr>\n<tr>\n<td>\u5df2\u5931\u8d25<\/td>\n<td><code>rejected<\/code><\/td>\n<td>\u8c03\u7528 <code>reject()<\/code> \u540e\u7684\u72b6\u6001<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u26a0\ufe0f <strong>\u6ce8\u610f<\/strong>\uff1aPromise \u72b6\u6001\u4e00\u65e6\u6539\u53d8\uff08\u4ece <code>pending<\/code> \u5230 <code>fulfilled<\/code> \u6216 <code>rejected<\/code>\uff09\uff0c\u5c31<strong>\u4e0d\u53ef\u9006\u8f6c<\/strong>\u3002<\/p>\n<hr>\n<h3>\u4e09\u3001return \u8bed\u53e5\u7684\u91cd\u8981\u6027<\/h3>\n<h4>3.1 \u4e3a\u4ec0\u4e48\u9700\u8981 return<\/h4>\n<pre><code class=\"javascript\">function createPromise() {\n    return new Promise((resolve, reject) =&gt; {\n        \/\/ \u6267\u884c\u5668\u51fd\u6570\u5185\u5bb9\n    });\n}<\/code><\/pre>\n<ul>\n<li>\u2705 <strong>\u5fc5\u987b\u5199 return<\/strong>\uff1a\u5c06\u521b\u5efa\u7684 Promise \u5bf9\u8c61\u8fd4\u56de\u7ed9\u5916\u90e8<\/li>\n<li>\u274c <strong>\u4e0d\u5199 return<\/strong>\uff1aPromise \u5185\u90e8\u903b\u8f91\u4ecd\u7136\u6267\u884c\uff0c\u4f46\u5916\u90e8\u65e0\u6cd5\u83b7\u5f97 Promise \u5bf9\u8c61<\/li>\n<li>\ud83d\udeab <strong>\u7ed3\u679c<\/strong>\uff1a\u65e0\u6cd5\u8c03\u7528 <code>.then()<\/code> \u548c <code>.catch()<\/code> \u65b9\u6cd5<\/li>\n<\/ul>\n<h4>3.2 \u6267\u884c\u65f6\u673a\u8bf4\u660e<\/h4>\n<pre><code class=\"javascript\">my_obj = createPromise(); \/\/ \u6b64\u65f6\u6267\u884c\u5668\u51fd\u6570\u7acb\u5373\u6267\u884c<\/code><\/pre>\n<ul>\n<li>\u6267\u884c\u5668\u51fd\u6570\u5728 <code>new Promise()<\/code> \u65f6<strong>\u7acb\u5373\u6267\u884c<\/strong>\uff08\u540c\u6b65\uff09<\/li>\n<li>\u4e0d\u9700\u8981\u8c03\u7528 <code>my_obj()<\/code> \u6765\u89e6\u53d1\u6267\u884c\u5668\u51fd\u6570<\/li>\n<li>Promise \u5bf9\u8c61\u521b\u5efa\u5b8c\u6210\u540e\u8fd4\u56de\u7ed9 <code>my_obj<\/code><\/li>\n<\/ul>\n<hr>\n<h3>\u56db\u3001then \u65b9\u6cd5\u8be6\u89e3<\/h3>\n<h4>4.1 \u57fa\u672c\u7528\u6cd5<\/h4>\n<pre><code class=\"javascript\">obj.then(result =&gt; console.log(result))<\/code><\/pre>\n<h4>4.2 \u8bed\u6cd5\u5206\u6790<\/h4>\n<ul>\n<li><code>then()<\/code> \u65b9\u6cd5\u63a5\u53d7\u4e00\u4e2a<strong>\u51fd\u6570<\/strong>\u4f5c\u4e3a\u53c2\u6570<\/li>\n<li>\n<p><code>result =&gt; console.log(result)<\/code> \u662f<strong>\u7bad\u5934\u51fd\u6570<\/strong>\uff08\u533f\u540d\u51fd\u6570\uff09<\/p>\n<ul>\n<li>\u53c2\u6570\uff1a<code>result<\/code><\/li>\n<li>\u51fd\u6570\u4f53\uff1a<code>console.log(result)<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>4.3 \u5de5\u4f5c\u539f\u7406<\/h4>\n<ol>\n<li>Promise \u72b6\u6001\u53d8\u4e3a <code>fulfilled<\/code><\/li>\n<li><code>then<\/code> \u65b9\u6cd5\u68c0\u6d4b\u5230\u72b6\u6001\u53d8\u5316<\/li>\n<li>\u81ea\u52a8\u8c03\u7528\u4f20\u5165\u7684\u56de\u8c03\u51fd\u6570<\/li>\n<li>\u5c06 Promise \u7684\u6210\u529f\u503c\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u56de\u8c03\u51fd\u6570<\/li>\n<\/ol>\n<h4>4.4 \u7b49\u4ef7\u5199\u6cd5<\/h4>\n<pre><code class=\"javascript\">\/\/ \u7bad\u5934\u51fd\u6570\nobj.then(result =&gt; console.log(result))\n\n\/\/ \u4f20\u7edf\u51fd\u6570\nobj.then(function(result) {\n    console.log(result);\n})\n\n\/\/ \u547d\u540d\u51fd\u6570\nfunction handleResult(result) {\n    console.log(result);\n}\nobj.then(handleResult)<\/code><\/pre>\n<hr>\n<h3>\u4e94\u3001Promise \u9759\u6001\u65b9\u6cd5<\/h3>\n<h4>5.1 \u6784\u9020\u51fd\u6570 vs \u9759\u6001\u65b9\u6cd5\u5bf9\u6bd4<\/h4>\n<table>\n<thead>\n<tr>\n<th>\u65b9\u6cd5<\/th>\n<th>\u662f\u5426\u6709\u6267\u884c\u5668\u51fd\u6570<\/th>\n<th>\u7528\u9014<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>new Promise()<\/code><\/td>\n<td>\u2705 \u6709<\/td>\n<td>\u521b\u5efa\u53ef\u63a7\u5236\u72b6\u6001\u7684 Promise<\/td>\n<\/tr>\n<tr>\n<td><code>Promise.resolve()<\/code><\/td>\n<td>\u274c \u6ca1\u6709<\/td>\n<td>\u76f4\u63a5\u521b\u5efa\u6210\u529f\u72b6\u6001\u7684 Promise<\/td>\n<\/tr>\n<tr>\n<td><code>Promise.reject()<\/code><\/td>\n<td>\u274c \u6ca1\u6709<\/td>\n<td>\u76f4\u63a5\u521b\u5efa\u5931\u8d25\u72b6\u6001\u7684 Promise<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>5.2 \u9759\u6001\u65b9\u6cd5\u5217\u8868<\/h4>\n<h5>\u5355\u4e2a Promise \u521b\u5efa<\/h5>\n<ul>\n<li><strong><code>Promise.resolve(value)<\/code><\/strong>\uff1a\u76f4\u63a5\u521b\u5efa <code>fulfilled<\/code> \u72b6\u6001\u7684 Promise<\/li>\n<li><strong><code>Promise.reject(reason)<\/code><\/strong>\uff1a\u76f4\u63a5\u521b\u5efa <code>rejected<\/code> \u72b6\u6001\u7684 Promise<\/li>\n<\/ul>\n<h5>\u591a\u4e2a Promise \u5904\u7406<\/h5>\n<ul>\n<li><strong><code>Promise.all([p1, p2, p3])<\/code><\/strong>\uff1a\u7b49\u5f85\u6240\u6709\u6210\u529f\uff0c\u4efb\u4e00\u5931\u8d25\u5219\u6574\u4f53\u5931\u8d25<\/li>\n<li><strong><code>Promise.race([p1, p2, p3])<\/code><\/strong>\uff1a\u8fd4\u56de\u6700\u5148\u5b8c\u6210\u7684 Promise \u7ed3\u679c<\/li>\n<li><strong><code>Promise.any([p1, p2, p3])<\/code><\/strong>\uff1a\u7b49\u5f85\u7b2c\u4e00\u4e2a\u6210\u529f\uff0c\u5168\u90e8\u5931\u8d25\u624d\u6574\u4f53\u5931\u8d25<\/li>\n<li><strong><code>Promise.allSettled([p1, p2, p3])<\/code><\/strong>\uff1a\u7b49\u5f85\u6240\u6709\u5b8c\u6210\uff0c\u8fd4\u56de\u6240\u6709\u7ed3\u679c<\/li>\n<\/ul>\n<h4>5.3 \u9759\u6001\u65b9\u6cd5\u5b58\u5728\u7684\u610f\u4e49<\/h4>\n<h5>\u7b80\u5316\u5e38\u89c1\u64cd\u4f5c<\/h5>\n<pre><code class=\"javascript\">\/\/ \u7e41\u7410\u5199\u6cd5\nnew Promise(resolve =&gt; resolve('\u7f13\u5b58\u6570\u636e'));\n\n\/\/ \u7b80\u6d01\u5199\u6cd5  \nPromise.resolve('\u7f13\u5b58\u6570\u636e');<\/code><\/pre>\n<h5>\u89e3\u51b3\u590d\u6742\u5f02\u6b65\u534f\u8c03<\/h5>\n<ul>\n<li><strong>\u5e76\u53d1\u63a7\u5236<\/strong>\uff1a<code>all<\/code>, <code>race<\/code>, <code>any<\/code>, <code>allSettled<\/code><\/li>\n<li><strong>\u8d85\u65f6\u5904\u7406<\/strong>\uff1a<code>race<\/code> \u914d\u5408 <code>setTimeout<\/code><\/li>\n<li><strong>\u5bb9\u9519\u673a\u5236<\/strong>\uff1a<code>any<\/code> \u63d0\u4f9b\u591a\u4e2a\u5907\u9009\u65b9\u6848<\/li>\n<li><strong>\u6279\u91cf\u5904\u7406<\/strong>\uff1a<code>allSettled<\/code> \u5904\u7406\u6279\u91cf\u64cd\u4f5c\u7ed3\u679c<\/li>\n<\/ul>\n<hr>\n<h3>\u516d\u3001\u5b8c\u6574\u793a\u4f8b\u5206\u6790<\/h3>\n<pre><code class=\"javascript\">function simple_promise() {\n    var my_promise = new Promise(function(resolve, reject) {\n        run_result = true;\n        if (run_result) {\n            resolve('\u8fd0\u884c\u6210\u529f');\n        } else {\n            reject('\u8fd0\u884c\u5931\u8d25');\n        }\n    });\n    return my_promise;\n}\n\nobj = simple_promise();\nobj.then(result =&gt; console.log(result))\n   .catch(reject =&gt; console.log(reject));<\/code><\/pre>\n<h4>\u6267\u884c\u6d41\u7a0b<\/h4>\n<ol>\n<li>\u8c03\u7528 <code>simple_promise()<\/code> \u51fd\u6570<\/li>\n<li>\u6267\u884c <code>new Promise()<\/code>\uff0c\u6267\u884c\u5668\u51fd\u6570<strong>\u7acb\u5373\u8fd0\u884c<\/strong><\/li>\n<li>\u6761\u4ef6\u5224\u65ad\uff0c\u8c03\u7528 <code>resolve('\u8fd0\u884c\u6210\u529f')<\/code><\/li>\n<li>Promise \u72b6\u6001\u53d8\u4e3a <code>fulfilled<\/code><\/li>\n<li>\u8fd4\u56de Promise \u5bf9\u8c61\u7ed9 <code>obj<\/code><\/li>\n<li><code>.then()<\/code> \u6ce8\u518c\u6210\u529f\u56de\u8c03\u51fd\u6570<\/li>\n<li>\u7531\u4e8e Promise \u5df2\u7ecf\u662f\u6210\u529f\u72b6\u6001\uff0c\u7acb\u5373\u6267\u884c\u56de\u8c03<\/li>\n<li><strong>\u8f93\u51fa<\/strong>\uff1a<code>\u8fd0\u884c\u6210\u529f<\/code><\/li>\n<\/ol>\n<hr>\n<h3>\u4e03\u3001\u5173\u952e\u7406\u89e3\u8981\u70b9<\/h3>\n<h4>\ud83d\udccc \u6838\u5fc3\u6982\u5ff5<\/h4>\n<ol>\n<li><strong>\u6267\u884c\u5668\u51fd\u6570<\/strong>\u662f\u533f\u540d\u51fd\u6570\uff0c\u5728 Promise \u521b\u5efa\u65f6<strong>\u7acb\u5373\u6267\u884c<\/strong><\/li>\n<li><strong>resolve\/reject<\/strong> \u662f\u51fd\u6570\u53c2\u6570\uff0c\u7531 JS \u5f15\u64ce\u63d0\u4f9b\uff0c\u7528\u4e8e\u6539\u53d8 Promise \u72b6\u6001<\/li>\n<li><strong>resolve() \u7684\u53c2\u6570<\/strong>\u4e0d\u662f\u8fd4\u56de\u503c\uff0c\u800c\u662f\u4f20\u9012\u7ed9 <code>.then()<\/code> \u7684\u503c<\/li>\n<li><strong>return \u5fc5\u4e0d\u53ef\u5c11<\/strong>\uff0c\u7528\u4e8e\u5c06 Promise \u5bf9\u8c61\u66b4\u9732\u7ed9\u5916\u90e8<\/li>\n<li><strong>\u9759\u6001\u65b9\u6cd5<\/strong>\u7b80\u5316\u64cd\u4f5c\uff0c\u89e3\u51b3\u590d\u6742\u5f02\u6b65\u573a\u666f\u7684\u534f\u8c03\u95ee\u9898<\/li>\n<li><strong>then \u65b9\u6cd5<\/strong>\u6ce8\u518c\u56de\u8c03\uff0cPromise \u72b6\u6001\u6539\u53d8\u65f6\u81ea\u52a8\u6267\u884c<\/li>\n<\/ol>\n<h4>\ud83c\udfaf \u6700\u4f73\u5b9e\u8df5<\/h4>\n<pre><code class=\"javascript\">\/\/ \u2705 \u63a8\u8350\u5199\u6cd5\uff1a\u6e05\u6670\u7684\u9519\u8bef\u5904\u7406\nfunction fetchData() {\n    return new Promise((resolve, reject) =&gt; {\n        \/\/ \u5f02\u6b65\u64cd\u4f5c\n        setTimeout(() =&gt; {\n            const success = Math.random() &gt; 0.5;\n            if (success) {\n                resolve({ data: '\u6570\u636e' });\n            } else {\n                reject(new Error('\u83b7\u53d6\u5931\u8d25'));\n            }\n        }, 1000);\n    });\n}\n\n\/\/ \u94fe\u5f0f\u8c03\u7528\nfetchData()\n    .then(result =&gt; {\n        console.log('\u6210\u529f:', result);\n        return result.data;\n    })\n    .catch(error =&gt; {\n        console.error('\u5931\u8d25:', error.message);\n    })\n    .finally(() =&gt; {\n        console.log('\u64cd\u4f5c\u5b8c\u6210');\n    });<\/code><\/pre>\n<hr>\n<h3>\u516b\u3001\u5e38\u89c1\u8bef\u533a\u4e0e\u9677\u9631<\/h3>\n<h4>\u274c \u9519\u8bef\u793a\u4f8b 1\uff1a\u5fd8\u8bb0 return<\/h4>\n<pre><code class=\"javascript\">function bad_promise() {\n    new Promise((resolve, reject) =&gt; {\n        resolve('\u6570\u636e');\n    });\n    \/\/ \u5fd8\u8bb0 return\uff0c\u5916\u90e8\u65e0\u6cd5\u83b7\u53d6 Promise\n}\n\nbad_promise().then(data =&gt; console.log(data)); \/\/ TypeError<\/code><\/pre>\n<h4>\u274c \u9519\u8bef\u793a\u4f8b 2\uff1a\u8bef\u89e3 resolve() \u4e3a\u8fd4\u56de\u503c<\/h4>\n<pre><code class=\"javascript\">function bad_example() {\n    return new Promise((resolve, reject) =&gt; {\n        const result = resolve('\u503c'); \/\/ resolve \u6ca1\u6709\u8fd4\u56de\u503c\n        console.log(result); \/\/ undefined\n    });\n}<\/code><\/pre>\n<h4>\u2705 \u6b63\u786e\u7406\u89e3<\/h4>\n<ul>\n<li><code>resolve()<\/code> \u53ea\u662f<strong>\u6539\u53d8\u72b6\u6001<\/strong>\u5e76<strong>\u4f20\u9012\u503c<\/strong>\u7ed9 <code>.then()<\/code><\/li>\n<li>\u4e0d\u8981\u5c06 <code>resolve()<\/code> \u5f53\u4f5c <code>return<\/code> \u4f7f\u7528<\/li>\n<\/ul>\n<hr>\n<h3>\u4e5d\u3001\u8fdb\u9636\u5e94\u7528\u573a\u666f<\/h3>\n<h4>\u573a\u666f 1\uff1a\u5e76\u53d1\u8bf7\u6c42\u63a7\u5236<\/h4>\n<pre><code class=\"javascript\">const promises = [\n    fetch('\/api\/user'),\n    fetch('\/api\/posts'),\n    fetch('\/api\/comments')\n];\n\nPromise.all(promises)\n    .then(responses =&gt; Promise.all(responses.map(r =&gt; r.json())))\n    .then(data =&gt; console.log('\u6240\u6709\u6570\u636e:', data))\n    .catch(error =&gt; console.error('\u67d0\u4e2a\u8bf7\u6c42\u5931\u8d25:', error));<\/code><\/pre>\n<h4>\u573a\u666f 2\uff1a\u8d85\u65f6\u63a7\u5236<\/h4>\n<pre><code class=\"javascript\">function timeoutPromise(promise, timeout) {\n    return Promise.race([\n        promise,\n        new Promise((_, reject) =&gt; \n            setTimeout(() =&gt; reject(new Error('\u8d85\u65f6')), timeout)\n        )\n    ]);\n}\n\ntimeoutPromise(fetch('\/api\/data'), 3000)\n    .then(data =&gt; console.log(data))\n    .catch(error =&gt; console.error(error.message));<\/code><\/pre>\n<h4>\u573a\u666f 3\uff1a\u5bb9\u9519\u5904\u7406<\/h4>\n<pre><code class=\"javascript\">const servers = [\n    fetch('https:\/\/server1.com\/api'),\n    fetch('https:\/\/server2.com\/api'),\n    fetch('https:\/\/server3.com\/api')\n];\n\nPromise.any(servers)\n    .then(response =&gt; console.log('\u7b2c\u4e00\u4e2a\u6210\u529f\u7684\u670d\u52a1\u5668\u54cd\u5e94:', response))\n    .catch(error =&gt; console.error('\u6240\u6709\u670d\u52a1\u5668\u90fd\u5931\u8d25\u4e86'));<\/code><\/pre>\n<hr>\n<h3>\u5341\u3001\u603b\u7ed3<\/h3>\n<p>Promise \u662f JavaScript \u5f02\u6b65\u7f16\u7a0b\u7684\u6838\u5fc3\u673a\u5236\uff0c\u638c\u63e1\u4ee5\u4e0b\u8981\u70b9\uff1a<\/p>\n<p>\u2705 \u7406\u89e3\u6267\u884c\u5668\u51fd\u6570\u7684<strong>\u7acb\u5373\u6267\u884c<\/strong>\u7279\u6027  <br \/>\u2705 \u638c\u63e1 <code>resolve<\/code>\/<code>reject<\/code> \u7684<strong>\u53c2\u6570\u4f20\u9012<\/strong>\u673a\u5236  <br \/>\u2705 \u719f\u7ec3\u4f7f\u7528 <code>.then()<\/code>\/<code>.catch()<\/code>\/<code>.finally()<\/code> \u94fe\u5f0f\u8c03\u7528  <br \/>\u2705 \u5584\u7528<strong>\u9759\u6001\u65b9\u6cd5<\/strong>\u5904\u7406\u590d\u6742\u5f02\u6b65\u573a\u666f  <br \/>\u2705 \u6ce8\u610f<strong>\u9519\u8bef\u5904\u7406<\/strong>\u548c<strong>\u72b6\u6001\u7ba1\u7406<\/strong><\/p>\n<blockquote><p>\ud83d\udca1 <strong>\u63d0\u793a<\/strong>\uff1aPromise \u662f <code>async\/await<\/code> \u7684\u57fa\u7840\uff0c\u6df1\u5165\u7406\u89e3 Promise \u6709\u52a9\u4e8e\u66f4\u597d\u5730\u4f7f\u7528\u73b0\u4ee3\u5f02\u6b65\u8bed\u6cd5\u3002<\/p><\/blockquote>\n<hr>\n<p><strong>\u53c2\u8003\u8d44\u6e90<\/strong>\uff1a<\/p>\n<ul>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=tNmj70eQFqr5OzP7RVdyAg%3D%3D.PeF0vJ%2FzKPx8TPZUyz2WZenzw63ZB6nLsooM7rrZdy2CKfd75cGxSBKNRLtXSvAOkrn7CoBT5q9M4k3HeWy2V5gCCkVUIRWo7UFguo41ezBTklm6jKdjoOLDXQK0qjGu\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">MDN &#8211; Promise<\/a><\/li>\n<li>[JavaScript.info &#8211; Promise](<a href=\"https:\/\/link.segmentfault.com\/?enc=Rd3%2BkcMdTbXjvTmPSxLVkw%3D%3D.KB5fspDegz2FGSh1kEuAqFlJOubwrMxKaggNVsmytE4IRdRwYe%2B6z%2FjbgfEH8bD9\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/zh.javascript.info\/promise-basics<\/a><\/li>\n<\/ul>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000047245776\">https:\/\/segmentfault.com\/a\/1190000047245776<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript Promise \u5b8c\u5168\u6307\u5357\uff1a\u4ece\u57fa\u7840\u5230\u8fdb\u9636 \u4e00\u3001Promise \u6784\u9020\u51fd\u6570\u57fa\u7840 1.1 \u57fa\u672c\u8bed [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10021081","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021081","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10021081"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021081\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10021081"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10021081"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10021081"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}