{"id":458,"date":"2023-03-27T09:11:32","date_gmt":"2023-03-27T01:11:32","guid":{"rendered":"http:\/\/yusemo.com\/?p=458"},"modified":"2023-03-27T12:16:26","modified_gmt":"2023-03-27T04:16:26","slug":"promise-then-%e5%bc%95%e5%8f%91%e7%9a%84%e5%a5%87%e6%80%9d%e5%a6%99%e6%83%b3","status":"publish","type":"post","link":"https:\/\/yusemo.com\/?p=458","title":{"rendered":"promise.then \u5f15\u53d1\u7684\u5947\u601d\u5999\u60f3"},"content":{"rendered":"<p>promise.then\uff1fPromise \u7684\u6210\u529f\u548c\u5931\u8d25\u60c5\u51b5\u7684\u56de\u8c03\u51fd\u6570<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/><\/div><\/td><td><div class=\"text codecolorer\">var p1 = new Promise((resolve, reject) =&gt; {<br \/>\nresolve('\u6210\u529f\uff01');<br \/>\n});<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>P1.then().then().then().then() \u5047\u8bbe\u4e2d\u95f4\u4e00\u4e2athen \u51fa\u9519\u4e86\u540e\u9762\u7684then\u4f1a\u6267\u884c\u5417\uff1f<\/p>\n<p>\u5199\u4e86\u591a\u5e74\u4ee3\u7801\u7684\u4f60\u80af\u5b9a\u8bf4\u88abcatch\u6389\u540e\u9762\u80af\u5b9a\u4e0d\u6267\u884c\u554a\uff01OTL~\u6ca1catch\u5462\uff1f\u5c31\u662f\u53ea\u662f\u95ee\u6267\u884c\u4e0d\u6267\u884c\uff1f<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/><\/div><\/td><td><div class=\"text codecolorer\">var p1 = new Promise((resolve, reject) =&gt;{<br \/>\n&nbsp; resolve(&quot;\u6210\u529f!&quot;);<br \/>\n});p1<br \/>\n&nbsp; &nbsp; .then(()=&gt;{console.info(1)})<br \/>\n&nbsp; &nbsp; .then(()=&gt;{throw new Error(&quot;\u51fa\u9519\u4e86&quot;;)})<br \/>\n&nbsp; &nbsp; .then(()=&gt;{console.info(3)},(e)=&gt;{console.info(e)})<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p><img decoding=\"async\" src=\"http:\/\/yusemo.com\/wp-content\/uploads\/2023\/03\/promise1.png\" alt=\"\" \/><\/p>\n<p>\u795e\u5947\u7684\u4e00\u5e55\u51fa\u73b0\u4e86\u5c45\u7136\u662f\u6267\u884c\u7684\u5e76\u4e14\u4f5c\u4e3a\u4e0b\u4e00\u4e2athen\u7684\u53c2\u6570\u4f20\u5165\u3002\u5176\u5b9ethen\u7684\u65b9\u6cd5\u65e9\u5728mdn\u4e0a\u6709\u89e3\u6790\u3002<\/p>\n<p>\u95ee\u9898\u53c8\u6765\u4e86\uff1f\u795e\u5947\u7684\u83dc\u9e1f\u95ee\u90a3\u7b2c\u4e8c\u4e2a\u9519\u4e86\uff0c\u7b2c\u4e09\u4e2a\u4f20\u5165\u4e86\u7b2c\u4e8c\u53c2\u6570\uff0c\u7b2c\u56db\u4e2a\u8fd8\u4f1a\u6267\u884c\u5417\uff1f<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/yusemo.com\/wp-content\/uploads\/2023\/03\/promise2.png\" alt=\"\" \/><br \/>\n\ufffc<br \/>\n\u771f\u662f\u795e\u5947\u3002\u5e76\u4e14\u540e\u9762\u7684then\u5c45\u7136\u662f\u8fd4\u56deresolve \u771f\u662f\u795e\u5947\u7684\u4e00\u5e55\u3002\u7ffb\u67e5mdn<br \/>\n<img decoding=\"async\" src=\"http:\/\/yusemo.com\/wp-content\/uploads\/2023\/03\/promise3.png\" alt=\"\" \/><\/p>\n<p>\u65e2\u7136then \u662f\u56de\u8c03\u51fd\u6570\u603b\u4f1a\u8fd4\u56de\u548c\u6267\u884c\u8fd9\u5c31\u4ea7\u751f\u65b0\u7684\u95ee\u9898\u4e86\uff1f\u90a3\u600e\u6837\u624d\u80fd\u4e2d\u65ad\u5462\uff1f<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/><\/div><\/td><td><div class=\"text codecolorer\">var p1 = new Promise((resolve, reject) =&gt; {<br \/>\nresolve('\u6210\u529f\uff01');<br \/>\n});p1<br \/>\n.then(()=&gt;{console.info(1)})<br \/>\n.then(()=&gt;{return new Promise((resolve,reject)=&gt;{})})<br \/>\n.then(()=&gt;{console.info(3)},(e)=&gt;{console.info('33')})<br \/>\n.then(()=&gt;{console.info(4)},(e)=&gt;{;console.info(e)})<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/yusemo.com\/wp-content\/uploads\/2023\/03\/promise4.png\" alt=\"\" width=\"542\" height=\"188\" class=\"alignnone size-full wp-image-462\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>promise.then\uff1fPromise \u7684\u6210\u529f\u548c\u5931\u8d25\u60c5\u51b5\u7684\u56de\u8c03\u51fd\u6570 123var p1 = new Prom [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/yusemo.com\/index.php?rest_route=\/wp\/v2\/posts\/458"}],"collection":[{"href":"https:\/\/yusemo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yusemo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yusemo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=458"}],"version-history":[{"count":7,"href":"https:\/\/yusemo.com\/index.php?rest_route=\/wp\/v2\/posts\/458\/revisions"}],"predecessor-version":[{"id":470,"href":"https:\/\/yusemo.com\/index.php?rest_route=\/wp\/v2\/posts\/458\/revisions\/470"}],"wp:attachment":[{"href":"https:\/\/yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}