{"id":2163,"date":"2025-05-05T10:07:45","date_gmt":"2025-05-05T02:07:45","guid":{"rendered":"https:\/\/zhuxinyong.com\/?p=2163"},"modified":"2025-05-05T10:09:22","modified_gmt":"2025-05-05T02:09:22","slug":"wei-shen-me-yao-qu-fen-hong-ren-wu-he-wei-ren-wu-t","status":"publish","type":"post","link":"https:\/\/zhuxinyong.com\/?p=2163","title":{"rendered":"\u4e3a\u4ec0\u4e48\u8981\u533a\u5206\u5b8f\u4efb\u52a1\u548c\u5fae\u4efb\u52a1\uff1f\u5b83\u4eec\u7684\u6267\u884c\u4f18\u5148\u7ea7\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2025\/05\/17464109477016.jpg\" alt=\"\" \/><\/p>\n<h2><a id=\"%F0%9F%A7%A0%E4%B8%BA%E4%BB%80%E4%B9%88%E8%A6%81%E5%8C%BA%E5%88%86%E5%AE%8F%E4%BB%BB%E5%8A%A1%EF%BC%88macro-task%EF%BC%89%E5%92%8C%E5%BE%AE%E4%BB%BB%E5%8A%A1%EF%BC%88micro-task%EF%BC%89%EF%BC%9F\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\ud83e\udde0 \u4e3a\u4ec0\u4e48\u8981\u533a\u5206\u5b8f\u4efb\u52a1\uff08Macro Task\uff09\u548c\u5fae\u4efb\u52a1\uff08Micro Task\uff09\uff1f<\/h2>\n<p>\u8fd9\u662f\u4e3a\u4e86\u66f4\u597d\u5730\u63a7\u5236 <strong>JavaScript \u7684\u6267\u884c\u987a\u5e8f\u548c\u54cd\u5e94\u6027\u80fd<\/strong>\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u5f02\u6b65\u4ee3\u7801\u65f6\uff1a<\/p>\n<ul>\n<li><strong>\u5fae\u4efb\u52a1<\/strong>\uff1a\u7528\u4e8e\u4fdd\u8bc1\u67d0\u4e9b\u64cd\u4f5c\u5728\u5f53\u524d\u5b8f\u4efb\u52a1\u7ed3\u675f\u524d\u7acb\u5373\u6267\u884c\uff08\u5982 <code>Promise.then()<\/code>\uff09\u3002<\/li>\n<li><strong>\u5b8f\u4efb\u52a1<\/strong>\uff1a\u7cfb\u7edf\u8c03\u5ea6\u7684\u4e3b\u5faa\u73af\u5355\u4f4d\uff08\u5982 <code>setTimeout()<\/code>\u3001<code>setInterval()<\/code>\u3001\u4e8b\u4ef6\u5904\u7406\uff09\u3002<\/li>\n<\/ul>\n<p>\ud83d\udc49 \u7b80\u5355\u8bf4\uff1a<strong>\u5fae\u4efb\u52a1\u662f\u201c\u7d27\u6025\u7684\u5c0f\u4e8b\u201d\uff0c\u5b8f\u4efb\u52a1\u662f\u201c\u4e0b\u4e00\u8f6e\u5927\u4e8b\u201d<\/strong>\u3002<\/p>\n<hr \/>\n<h2><a id=\"%F0%9F%93%8A%E6%89%A7%E8%A1%8C%E4%BC%98%E5%85%88%E7%BA%A7%E9%A1%BA%E5%BA%8F%EF%BC%88%E4%BA%8B%E4%BB%B6%E5%BE%AA%E7%8E%AF%E6%A8%A1%E5%9E%8B%EF%BC%89\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\ud83d\udcca \u6267\u884c\u4f18\u5148\u7ea7\u987a\u5e8f\uff08\u4e8b\u4ef6\u5faa\u73af\u6a21\u578b\uff09<\/h2>\n<ol>\n<li>\u6267\u884c\u4e00\u4e2a <strong>\u5b8f\u4efb\u52a1<\/strong>\uff08\u5982\u4e3b\u7ebf\u7a0b\u4ee3\u7801\u6216 <code>setTimeout<\/code> \u56de\u8c03\uff09<\/li>\n<li>\u6267\u884c\u6240\u6709\u4ea7\u751f\u7684 <strong>\u5fae\u4efb\u52a1<\/strong>\uff08\u5982 <code>Promise.then()<\/code>\u3001<code>queueMicrotask()<\/code>\uff09<\/li>\n<li>\u6e32\u67d3\u66f4\u65b0\uff08\u5982 DOM \u6539\u52a8\uff09<\/li>\n<li>\u5f00\u59cb\u4e0b\u4e00\u8f6e\u5b8f\u4efb\u52a1<\/li>\n<\/ol>\n<hr \/>\n<h2><a id=\"%E2%9C%85%E4%B8%BE%E4%B8%AA%E4%BE%8B%E5%AD%90%EF%BC%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u2705 \u4e3e\u4e2a\u4f8b\u5b50\uff1a<\/h2>\n<pre><code class=\"language-js\">console.log('start');\n\nsetTimeout(() =&gt; {\n  console.log('macro task');\n});\n\nPromise.resolve().then(() =&gt; {\n  console.log('micro task');\n});\n\nconsole.log('end');\n<\/code><\/pre>\n<h3><a id=\"%E8%BE%93%E5%87%BA%E9%A1%BA%E5%BA%8F%EF%BC%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u8f93\u51fa\u987a\u5e8f\uff1a<\/h3>\n<pre><code class=\"language-plain_text\">start\nend\nmicro task     \/\/ \u5fae\u4efb\u52a1\u4f18\u5148\nmacro task     \/\/ \u5b8f\u4efb\u52a1\u4e4b\u540e\n<\/code><\/pre>\n<hr \/>\n<h2><a id=\"%F0%9F%93%A6%E6%80%BB%E7%BB%93\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\ud83d\udce6 \u603b\u7ed3<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u7c7b\u578b<\/th>\n<th>\u793a\u4f8b<\/th>\n<th>\u4f55\u65f6\u6267\u884c<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u5fae\u4efb\u52a1<\/td>\n<td><code>Promise.then()<\/code>\u3001<code>queueMicrotask()<\/code><\/td>\n<td>\u5f53\u524d\u5b8f\u4efb\u52a1\u7ed3\u675f\u540e\uff0c\u7acb\u523b\u6267\u884c\u6240\u6709<\/td>\n<\/tr>\n<tr>\n<td>\u5b8f\u4efb\u52a1<\/td>\n<td><code>setTimeout()<\/code>\u3001\u4e8b\u4ef6\u76d1\u542c\u56de\u8c03<\/td>\n<td>\u6bcf\u4e00\u8f6e\u4e8b\u4ef6\u5faa\u73af\u7684\u8d77\u70b9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>\ud83e\udde0 \u4e3a\u4ec0\u4e48\u8981\u533a\u5206\u5b8f\u4efb\u52a1\uff08Macro Task\uff09\u548c\u5fae\u4efb\u52a1\uff08Micro Task\uff09\uff1f \u8fd9\u662f\u4e3a\u4e86\u66f4\u597d\u5730\u63a7\u5236&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,3],"tags":[265],"class_list":["post-2163","post","type-post","status-publish","format-standard","hentry","category-frontend","category-tech","tag-wiki"],"_links":{"self":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/2163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2163"}],"version-history":[{"count":1,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/2163\/revisions"}],"predecessor-version":[{"id":2164,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/2163\/revisions\/2164"}],"wp:attachment":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}