{"id":3880,"date":"2024-11-10T16:23:38","date_gmt":"2024-11-10T08:23:38","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3880\/"},"modified":"2024-11-10T16:23:38","modified_gmt":"2024-11-10T08:23:38","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88%e4%b8%a4%e4%b8%aa%e9%98%b2%e6%8a%96%e4%bb%a3%e7%a0%81%e7%89%88%e6%9c%ac%e8%a1%a8%e7%8e%b0%e5%b7%ae%e5%bc%82%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3880\/","title":{"rendered":"\u4e3a\u4ec0\u4e48\u4e24\u4e2a\u9632\u6296\u4ee3\u7801\u7248\u672c\u8868\u73b0\u5dee\u5f02\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173115774481323.jpg\" class=\"aligncenter\" title=\"\u4e3a\u4ec0\u4e48\u4e24\u4e2a\u9632\u6296\u4ee3\u7801\u7248\u672c\u8868\u73b0\u5dee\u5f02\uff1f\u63d2\u56fe\" alt=\"\u4e3a\u4ec0\u4e48\u4e24\u4e2a\u9632\u6296\u4ee3\u7801\u7248\u672c\u8868\u73b0\u5dee\u5f02\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u9632\u6296\u4ee3\u7801\u8868\u73b0\u5dee\u5f02\uff1a\u63a2\u7a76\u7248\u672c\u5dee\u5f02\u7684\u5f71\u54cd<\/strong><\/p>\n<p>\u8ba8\u8bba\u4e2d\u63d0\u5230\u7684\u4e24\u4e2a\u9632\u6296\u4ee3\u7801\u7248\u672c\u5b58\u5728\u4e00\u4e2a\u7ec6\u5fae\u5dee\u5f02\uff1a\u5982\u679c\u5728\u7279\u5b9a\u6761\u4ef6\u4e0b\u8c03\u7528\u51fd\u6570\uff0cdebounce-version1 \u7684\u6267\u884c\u7ed3\u679c\u4e0e\u9884\u671f\u4e0d\u7b26\uff0c\u800c debounce-version2 \u5219\u8fd0\u884c\u6b63\u5e38\u3002<\/p>\n<p><strong>\u7248\u672c\u5dee\u5f02<\/strong><\/p>\n<p>debounce-version1 \u4e0e debounce-version2 \u7684\u552f\u4e00\u5728\u4e8e\u79fb\u52a8\u4e86\u4ee5\u4e0b\u4ee3\u7801\u5757\u7684\u4f4d\u7f6e\uff1a<\/p>\n<pre>    if (notCalled &amp;&amp; immediate) result = func.apply(context, args);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728 debounce-version1 \u4e2d\uff0c\u6b64\u5757\u4ee3\u7801\u653e\u7f6e\u5728 setTimeout \u56de\u8c03\u51fd\u6570\u4e2d\uff0c\u800c\u5728 debounce-version2 \u4e2d\uff0c\u5b83\u88ab\u79fb\u52a8\u5230 debounced \u51fd\u6570\u7684\u5f00\u5934\u3002<\/p>\n<p><strong>\u95ee\u9898\u6839\u6e90<\/strong><\/p>\n<p>\u4e24\u4e2a\u7248\u672c\u4e4b\u95f4\u7684\u5dee\u5f02\u5bfc\u81f4\u4e86\u9632\u6296\u884c\u4e3a\u7684\u4e0d\u540c\u3002\u7531\u4e8e func.apply(&#8230;) \u662f\u4e00\u4e2a\u540c\u6b65\u65b9\u6cd5\uff0c\u5b83\u4f1a\u7acb\u5373\u6267\u884c\u6307\u5b9a\u7684\u51fd\u6570\u3002\u5728 debounce-version1 \u4e2d\uff0c\u5982\u679c\u5728\u7279\u5b9a\u6761\u4ef6\u4e0b\u8c03\u7528\u51fd\u6570\uff0c\u6b64\u65b9\u6cd5\u5c06\u5728 setTimeout \u56de\u8c03\u51fd\u6570\u6267\u884c\u4e4b\u524d\u6267\u884c\u3002\u56e0\u6b64\uff0cnotCalled \u59cb\u7ec8\u4e3a true\uff0c\u5bfc\u81f4\u51fd\u6570\u591a\u6b21\u6267\u884c\u3002<\/p>\n<p><strong>\u6b63\u786e\u7248\u672c<\/strong><\/p>\n<p>debounce-version2 \u7684\u4f4d\u7f6e\u6b63\u786e\uff0c\u5b83\u5728\u8bbe\u7f6e\u8d85\u65f6\u4e4b\u524d\u68c0\u67e5 notCalled \u7684\u503c\u3002\u8fd9\u786e\u4fdd\u4e86\u51fd\u6570\u53ea\u5728\u8d85\u65f6\u65f6\u95f4\u8fc7\u540e\u624d\u6267\u884c\uff0c\u4ece\u800c\u5b9e\u73b0\u4e86\u9884\u671f\u7684\u9632\u6296\u884c\u4e3a\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e24\u4e2a\u9632\u6296\u4ee3\u7801\u7248\u672c\u8868\u73b0\u5dee\u5f02\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9632\u6296\u4ee3\u7801\u8868\u73b0\u5dee\u5f02\uff1a\u63a2\u7a76\u7248\u672c\u5dee\u5f02\u7684\u5f71\u54cd \u8ba8\u8bba\u4e2d\u63d0\u5230\u7684\u4e24\u4e2a\u9632\u6296\u4ee3\u7801\u7248\u672c\u5b58\u5728\u4e00\u4e2a\u7ec6\u5fae\u5dee\u5f02\uff1a\u5982\u679c\u5728\u7279\u5b9a\u6761\u4ef6\u4e0b\u8c03\u7528\u51fd\u6570\uff0cdebounce-version1 \u7684\u6267\u884c\u7ed3\u679c\u4e0e\u9884\u671f\u4e0d\u7b26\uff0c\u800c debounce-version2 \u5219\u8fd0\u884c\u6b63\u5e38\u3002 \u7248\u672c\u5dee\u5f02 debounce-version1 \u4e0e debounce-version2 \u7684\u552f\u4e00\u5728\u4e8e\u79fb\u52a8\u4e86\u4ee5\u4e0b\u4ee3\u7801\u5757\u7684\u4f4d\u7f6e\uff1a if (notCalled &amp;&amp; immediate) result = func.apply(context, args); \u767b\u5f55\u540e\u590d\u5236 \u5728 debounce-version1 \u4e2d\uff0c\u6b64\u5757\u4ee3\u7801\u653e\u7f6e\u5728 setTimeout \u56de\u8c03\u51fd\u6570\u4e2d\uff0c\u800c\u5728 debounce-version2 \u4e2d\uff0c\u5b83\u88ab\u79fb\u52a8\u5230 debounced \u51fd\u6570\u7684\u5f00\u5934\u3002 \u95ee\u9898\u6839\u6e90 \u4e24\u4e2a\u7248\u672c\u4e4b\u95f4\u7684\u5dee\u5f02\u5bfc\u81f4\u4e86\u9632\u6296\u884c\u4e3a\u7684\u4e0d\u540c\u3002\u7531\u4e8e func.apply(&#8230;) \u662f\u4e00\u4e2a\u540c\u6b65\u65b9\u6cd5\uff0c\u5b83\u4f1a\u7acb\u5373\u6267\u884c\u6307\u5b9a\u7684\u51fd\u6570\u3002\u5728 debounce-version1 \u4e2d\uff0c\u5982\u679c\u5728\u7279\u5b9a\u6761\u4ef6\u4e0b\u8c03\u7528\u51fd\u6570\uff0c\u6b64\u65b9\u6cd5\u5c06\u5728 setTimeout \u56de\u8c03\u51fd\u6570\u6267\u884c\u4e4b\u524d\u6267\u884c\u3002\u56e0\u6b64\uff0cnotCalled \u59cb\u7ec8\u4e3a true\uff0c\u5bfc\u81f4\u51fd\u6570\u591a\u6b21\u6267\u884c\u3002 \u6b63\u786e\u7248\u672c debounce-version2 \u7684\u4f4d\u7f6e\u6b63\u786e\uff0c\u5b83\u5728\u8bbe\u7f6e\u8d85\u65f6\u4e4b\u524d\u68c0\u67e5 notCalled \u7684\u503c\u3002\u8fd9\u786e\u4fdd\u4e86\u51fd\u6570\u53ea\u5728\u8d85\u65f6\u65f6\u95f4\u8fc7\u540e\u624d\u6267\u884c\uff0c\u4ece\u800c\u5b9e\u73b0\u4e86\u9884\u671f\u7684\u9632\u6296\u884c\u4e3a\u3002 \u4ee5\u4e0a\u5c31\u662f\u4e24\u4e2a\u9632\u6296\u4ee3\u7801\u7248\u672c\u8868\u73b0\u5dee\u5f02\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-3880","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3880","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=3880"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3880\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3880"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3880"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3880"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}