{"id":1427,"date":"2025-02-08T00:42:23","date_gmt":"2025-02-07T16:42:23","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=1427"},"modified":"2025-02-08T00:42:24","modified_gmt":"2025-02-07T16:42:24","slug":"%e8%a7%a3%e5%86%b3javascript%e5%bc%80%e5%8f%91%e4%b8%ad%e5%b8%b8%e8%a7%81%e9%94%99%e8%af%af%e9%97%ae%e9%a2%98%ef%bc%9a%e6%a0%b9%e6%9c%ac%e5%8e%9f%e5%9b%a0%e4%b8%8e%e8%af%a6%e7%bb%86%e8%a7%a3%e5%86%b3","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/02\/08\/%e8%a7%a3%e5%86%b3javascript%e5%bc%80%e5%8f%91%e4%b8%ad%e5%b8%b8%e8%a7%81%e9%94%99%e8%af%af%e9%97%ae%e9%a2%98%ef%bc%9a%e6%a0%b9%e6%9c%ac%e5%8e%9f%e5%9b%a0%e4%b8%8e%e8%af%a6%e7%bb%86%e8%a7%a3%e5%86%b3\/","title":{"rendered":"\u89e3\u51b3JavaScript\u5f00\u53d1\u4e2d\u5e38\u89c1\u9519\u8bef\u95ee\u9898\uff1a\u6839\u672c\u539f\u56e0\u4e0e\u8be6\u7ec6\u89e3\u51b3\u65b9\u6848"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728JavaScript\u5f00\u53d1\u4e2d\uff0c\u8bb8\u591a\u5e38\u89c1\u7684\u9519\u8bef\u95ee\u9898\u6e90\u4e8e\u57fa\u7840\u77e5\u8bc6\u7684\u4e0d\u8db3\u6216\u8bef\u7528\u3002\u672c\u6587\u5c06\u9488\u5bf9JavaScript\u5f00\u53d1\u4e2d\u7ecf\u5e38\u9047\u5230\u7684\u9519\u8bef\uff0c\u8be6\u7ec6\u5206\u6790\u5176\u6839\u672c\u539f\u56e0\uff0c\u5e76\u63d0\u4f9b\u660e\u786e\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>\u672a\u58f0\u660e\u7684\u53d8\u91cf<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u95ee\u9898\u6839\u6e90\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5f53\u5f00\u53d1\u8005\u5728\u4f7f\u7528\u4e00\u4e2a\u53d8\u91cf\u4e4b\u524d\u6ca1\u6709\u663e\u5f0f\u58f0\u660e\u5b83\u65f6\uff0cJavaScript\u4f1a\u5c06\u5b83\u81ea\u52a8\u521b\u5efa\u4e3a\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf\u3002\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u53d8\u91cf\u610f\u5916\u5730\u5f71\u54cd\u5168\u5c40\u72b6\u6001\uff0c\u5c24\u5176\u662f\u5728\u5927\u578b\u5e94\u7528\u4e2d\uff0c\u8fd9\u79cd\u95ee\u9898\u53ef\u80fd\u4f1a\u5f15\u53d1\u4e00\u4e9b\u96be\u4ee5\u8ffd\u8e2a\u7684bug\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u603b\u662f\u663e\u5f0f\u58f0\u660e\u53d8\u91cf<\/strong>\uff1a\u59cb\u7ec8\u4f7f\u7528<code>let<\/code>\u3001<code>const<\/code>\uff08ES6\uff09\u6216\u8005<code>var<\/code>\uff08\u8001\u7248\u672c\uff09\u6765\u58f0\u660e\u53d8\u91cf\u3002<code>let<\/code>\u548c<code>const<\/code>\u662f\u5757\u7ea7\u4f5c\u7528\u57df\u7684\uff0c\u800c<code>var<\/code>\u662f\u51fd\u6570\u7ea7\u4f5c\u7528\u57df\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u9519\u8bef\u793a\u4f8b\uff1a\nx = 10; \/\/ \u5982\u679c\u6ca1\u6709\u58f0\u660ex\uff0c\u5b83\u4f1a\u6210\u4e3a\u5168\u5c40\u53d8\u91cf\nconsole.log(x);  \/\/ 10\n\n\/\/ \u6b63\u786e\u793a\u4f8b\uff1a\nlet x = 10;\nconsole.log(x);  \/\/ 10<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>\u53d8\u91cf\u63d0\u5347\uff08Hoisting\uff09<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u95ee\u9898\u6839\u6e90\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>var<\/code>\u58f0\u660e\u7684\u53d8\u91cf\u4f1a\u88ab\u63d0\u5347\u5230\u4f5c\u7528\u57df\u7684\u9876\u90e8\uff0c\u4f46\u8d4b\u503c\u4e0d\u4f1a\u63d0\u5347\u3002\u8fd9\u53ef\u80fd\u5bfc\u81f4\u4f60\u5728\u53d8\u91cf\u58f0\u660e\u4e4b\u524d\u4f7f\u7528\u5b83\u4eec\u65f6\u5f97\u5230<code>undefined<\/code>\uff0c\u800c\u4e0d\u662f\u4f60\u671f\u671b\u7684\u503c\u3002<\/li>\n\n\n\n<li>\u5bf9\u4e8e<code>let<\/code>\u548c<code>const<\/code>\uff0c\u867d\u7136\u5b83\u4eec\u5728\u4f5c\u7528\u57df\u5185\u58f0\u660e\uff0c\u4f46\u662f\u4f1a\u5728\u58f0\u660e\u4e4b\u524d\u5904\u4e8e\u201c\u6682\u65f6\u6027\u6b7b\u533a\u201d\uff08TDZ\uff09\uff0c\u8bbf\u95ee\u5b83\u4eec\u4f1a\u629b\u51fa<code>ReferenceError<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528<code>let<\/code>\u548c<code>const<\/code>\u4ee3\u66ff<code>var<\/code><\/strong>\uff1a\u907f\u514d\u4f7f\u7528<code>var<\/code>\uff0c\u51cf\u5c11\u56e0\u53d8\u91cf\u63d0\u5347\u800c\u4ea7\u751f\u7684\u9519\u8bef\u3002<\/li>\n\n\n\n<li><strong>\u59cb\u7ec8\u5728\u58f0\u660e\u4e4b\u524d\u4f7f\u7528\u53d8\u91cf<\/strong>\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u9519\u8bef\u793a\u4f8b\uff1a\nconsole.log(a); \/\/ undefined\nvar a = 5;\n\n\/\/ \u6b63\u786e\u793a\u4f8b\uff1a\nlet b = 10;\nconsole.log(b); \/\/ 10<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>\u7c7b\u578b\u8f6c\u6362\u95ee\u9898<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u95ee\u9898\u6839\u6e90\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>JavaScript\u6709\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\uff08type coercion\uff09\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u64cd\u4f5c\u7b26\u4f1a\u81ea\u52a8\u5c06\u4e0d\u540c\u7c7b\u578b\u7684\u503c\u8f6c\u6362\u4e3a\u517c\u5bb9\u7684\u7c7b\u578b\u3002\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4e0d\u7b26\u5408\u9884\u671f\u7684\u7ed3\u679c\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528\u4e25\u683c\u76f8\u7b49 <code>===<\/code> \u6bd4\u8f83<\/strong>\uff1a\u4f7f\u7528<code>===<\/code>\u6765\u907f\u514d\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\uff0c\u786e\u4fdd\u503c\u548c\u7c7b\u578b\u90fd\u76f8\u7b49\u3002<\/li>\n\n\n\n<li><strong>\u663e\u5f0f\u7c7b\u578b\u8f6c\u6362<\/strong>\uff1a\u5982\u679c\u4f60\u9700\u8981\u8f6c\u6362\u6570\u636e\u7c7b\u578b\uff0c\u53ef\u4ee5\u4f7f\u7528\u663e\u5f0f\u8f6c\u6362\u65b9\u6cd5\uff0c\u5982<code>String()<\/code>\u3001<code>Number()<\/code>\u3001<code>Boolean()<\/code>\u7b49\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u9519\u8bef\u793a\u4f8b\uff1a\nconsole.log(5 + '5'); \/\/ \"55\"\uff0c\u5b57\u7b26\u4e32\u62fc\u63a5\n\n\/\/ \u6b63\u786e\u793a\u4f8b\uff1a\nconsole.log(5 + Number('5'));  \/\/ 10\uff0c\u6570\u5b57\u76f8\u52a0<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong><code>this<\/code>\u6307\u5411\u95ee\u9898<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u95ee\u9898\u6839\u6e90\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728JavaScript\u4e2d\uff0c<code>this<\/code>\u7684\u6307\u5411\u662f\u7531\u51fd\u6570\u8c03\u7528\u7684\u4e0a\u4e0b\u6587\u51b3\u5b9a\u7684\uff0c\u5c24\u5176\u662f\u5728\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\u3001\u56de\u8c03\u51fd\u6570\u548c\u5b9a\u65f6\u5668\u4e2d\uff0c<code>this<\/code>\u7684\u6307\u5411\u53ef\u80fd\u548c\u4f60\u9884\u671f\u7684\u4e0d\u540c\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528<code>bind()<\/code><\/strong>\uff1a\u4f7f\u7528<code>bind()<\/code>\u65b9\u6cd5\u660e\u786e\u6307\u5b9a<code>this<\/code>\u7684\u503c\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528\u7bad\u5934\u51fd\u6570<\/strong>\uff1a\u7bad\u5934\u51fd\u6570\u4e0d\u4f1a\u7ed1\u5b9a\u81ea\u5df1\u7684<code>this<\/code>\uff0c\u5b83\u4f1a\u7ee7\u627f\u5916\u5c42\u4f5c\u7528\u57df\u7684<code>this<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u9519\u8bef\u793a\u4f8b\uff1a\nfunction Counter() {\n  this.count = 0;\n  setInterval(function() {\n    console.log(this.count); \/\/ `this`\u6307\u5411\u5168\u5c40\u5bf9\u8c61\n    this.count++;\n  }, 1000);\n}\n\n\/\/ \u6b63\u786e\u793a\u4f8b1\uff1a\u4f7f\u7528 `bind()` \u7ed1\u5b9a `this`\nfunction Counter() {\n  this.count = 0;\n  setInterval(function() {\n    console.log(this.count);  \/\/ \u6b63\u786e\u8f93\u51fa\n    this.count++;\n  }.bind(this), 1000);\n}\n\n\/\/ \u6b63\u786e\u793a\u4f8b2\uff1a\u4f7f\u7528\u7bad\u5934\u51fd\u6570\nfunction Counter() {\n  this.count = 0;\n  setInterval(() =&gt; {\n    console.log(this.count);  \/\/ \u6b63\u786e\u8f93\u51fa\n    this.count++;\n  }, 1000);\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>\u56de\u8c03\u5730\u72f1\uff08Callback Hell\uff09<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u95ee\u9898\u6839\u6e90\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5f53\u4f60\u6709\u591a\u4e2a\u5d4c\u5957\u7684\u56de\u8c03\u51fd\u6570\u65f6\uff0c\u4ee3\u7801\u4f1a\u53d8\u5f97\u96be\u4ee5\u7ef4\u62a4\u3001\u8c03\u8bd5\u548c\u9605\u8bfb\u3002\u56de\u8c03\u5730\u72f1\u901a\u5e38\u53d1\u751f\u5728\u5904\u7406\u5f02\u6b65\u64cd\u4f5c\u65f6\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528<code>Promise<\/code><\/strong>\uff1a\u901a\u8fc7<code>Promise<\/code>\u53ef\u4ee5\u8ba9\u5f02\u6b65\u64cd\u4f5c\u6309\u987a\u5e8f\u6267\u884c\uff0c\u907f\u514d\u56de\u8c03\u5730\u72f1\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528<code>async\/await<\/code><\/strong>\uff1a<code>async\/await<\/code>\u662f\u57fa\u4e8e<code>Promise<\/code>\u7684\u8bed\u6cd5\u7cd6\uff0c\u5b83\u4f7f\u5f97\u5f02\u6b65\u4ee3\u7801\u66f4\u52a0\u76f4\u89c2\u548c\u7b80\u6d01\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u9519\u8bef\u793a\u4f8b\uff1a\u56de\u8c03\u5730\u72f1\nfs.readFile('file1.txt', function(err, data1) {\n  fs.readFile('file2.txt', function(err, data2) {\n    fs.readFile('file3.txt', function(err, data3) {\n      \/\/ \u7ee7\u7eed\u5d4c\u5957\n    });\n  });\n});\n\n\/\/ \u6b63\u786e\u793a\u4f8b\uff1a\u4f7f\u7528 Promise\nfs.promises.readFile('file1.txt')\n  .then(data1 =&gt; fs.promises.readFile('file2.txt'))\n  .then(data2 =&gt; fs.promises.readFile('file3.txt'))\n  .then(data3 =&gt; console.log('Done'))\n  .catch(err =&gt; console.error(err));\n\n\/\/ \u4f7f\u7528 async\/await\nasync function readFiles() {\n  try {\n    const data1 = await fs.promises.readFile('file1.txt');\n    const data2 = await fs.promises.readFile('file2.txt');\n    const data3 = await fs.promises.readFile('file3.txt');\n    console.log('Done');\n  } catch (err) {\n    console.error(err);\n  }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6. <strong>\u4f5c\u7528\u57df\u548c\u95ed\u5305\u95ee\u9898<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u95ee\u9898\u6839\u6e90\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728JavaScript\u4e2d\uff0c\u51fd\u6570\u521b\u5efa\u4e86\u4e00\u4e2a\u65b0\u7684\u4f5c\u7528\u57df\uff0c\u95ed\u5305\u4f1a\u201c\u8bb0\u4f4f\u201d\u5b83\u88ab\u521b\u5efa\u65f6\u7684\u4f5c\u7528\u57df\u3002\u95ed\u5305\u6709\u65f6\u4f1a\u5bfc\u81f4\u9884\u671f\u4e4b\u5916\u7684\u884c\u4e3a\uff0c\u5c24\u5176\u662f\u5728\u5faa\u73af\u4e2d\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528<code>let<\/code>\u6765\u5b9a\u4e49\u5faa\u73af\u53d8\u91cf<\/strong>\uff1a<code>let<\/code>\u4f1a\u4e3a\u6bcf\u6b21\u8fed\u4ee3\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u4f5c\u7528\u57df\uff0c\u800c<code>var<\/code>\u4e0d\u4f1a\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528<code>bind()<\/code>\u65b9\u6cd5\u6216\u7bad\u5934\u51fd\u6570<\/strong>\uff1a\u786e\u4fdd\u6bcf\u4e2a\u56de\u8c03\u90fd\u80fd\u83b7\u53d6\u6b63\u786e\u7684<code>this<\/code>\u6216\u4f5c\u7528\u57df\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u9519\u8bef\u793a\u4f8b\uff1a\u95ed\u5305\u95ee\u9898\uff0c\u4f7f\u7528`var`\nfor (var i = 0; i &lt; 5; i++) {\n  setTimeout(function() {\n    console.log(i);  \/\/ \u8f93\u51fa5\u6b215\uff0c\u800c\u4e0d\u662f0\u52304\n  }, 1000);\n}\n\n\/\/ \u6b63\u786e\u793a\u4f8b\uff1a\u4f7f\u7528 `let`\uff0c\u6bcf\u6b21\u8fed\u4ee3\u521b\u5efa\u65b0\u7684\u4f5c\u7528\u57df\nfor (let i = 0; i &lt; 5; i++) {\n  setTimeout(function() {\n    console.log(i);  \/\/ \u8f93\u51fa0\u52304\n  }, 1000);\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">7. <strong>\u6570\u7ec4\u548c\u5bf9\u8c61\u64cd\u4f5c\u9519\u8bef<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u95ee\u9898\u6839\u6e90\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6d45\u62f7\u8d1d<\/strong>\uff1a\u5982\u679c\u4f60\u5bf9\u5bf9\u8c61\u6216\u6570\u7ec4\u8fdb\u884c\u8d4b\u503c\u6216\u62f7\u8d1d\u64cd\u4f5c\uff0c\u5b9e\u9645\u4e0a\u53ef\u80fd\u662f\u590d\u5236\u4e86\u5f15\u7528\uff0c\u5bfc\u81f4\u4fee\u6539\u4e00\u4e2a\u5bf9\u8c61\u65f6\u53e6\u4e00\u4e2a\u5bf9\u8c61\u4e5f\u88ab\u4fee\u6539\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6d45\u62f7\u8d1d<\/strong>\uff1a\u4f7f\u7528<code>Object.assign()<\/code>\u6216\u5c55\u5f00\u8fd0\u7b97\u7b26\uff08<code>...<\/code>\uff09\u8fdb\u884c\u6d45\u62f7\u8d1d\u3002<\/li>\n\n\n\n<li><strong>\u6df1\u62f7\u8d1d<\/strong>\uff1a\u5bf9\u4e8e\u5d4c\u5957\u5bf9\u8c61\u6216\u6570\u7ec4\uff0c\u4f7f\u7528<code>JSON.parse(JSON.stringify())<\/code>\u8fdb\u884c\u6df1\u62f7\u8d1d\uff0c\u6216\u8005\u4f7f\u7528\u5982<code>Lodash<\/code>\u7684<code>cloneDeep()<\/code>\u65b9\u6cd5\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u9519\u8bef\u793a\u4f8b\uff1a\u6d45\u62f7\u8d1d\uff0c\u4fee\u6539\u5b50\u5bf9\u8c61\u4f1a\u5f71\u54cd\u5176\u4ed6\u5bf9\u8c61\nlet obj1 = { a: 1, b: { c: 2 } };\nlet obj2 = Object.assign({}, obj1);\nobj2.b.c = 3;\n\nconsole.log(obj1.b.c);  \/\/ 3\uff0cobj1\u4e5f\u88ab\u4fee\u6539\n\n\/\/ \u6b63\u786e\u793a\u4f8b\uff1a\u6df1\u62f7\u8d1d\nlet obj3 = JSON.parse(JSON.stringify(obj1));\nobj3.b.c = 4;\nconsole.log(obj1.b.c);  \/\/ 2\uff0cobj1\u6ca1\u6709\u53d8\u5316<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">8. <strong>\u4e8b\u4ef6\u7ed1\u5b9a\u95ee\u9898<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u95ee\u9898\u6839\u6e90\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728\u7ed1\u5b9a\u4e8b\u4ef6\u65f6\uff0c\u5982\u679c\u6ca1\u6709\u6b63\u786e\u79fb\u9664\u4e8b\u4ef6\u76d1\u542c\u5668\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5185\u5b58\u6cc4\u6f0f\uff0c\u6216\u8005\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\u88ab\u591a\u6b21\u6267\u884c\u3002<\/li>\n\n\n\n<li>\u4e8b\u4ef6\u7684<code>this<\/code>\u6307\u5411\u6709\u65f6\u4e5f\u4f1a\u5bfc\u81f4\u9519\u8bef\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u79fb\u9664\u4e8b\u4ef6\u76d1\u542c\u5668<\/strong>\uff1a\u5f53\u4e0d\u518d\u9700\u8981\u76d1\u542c\u5668\u65f6\uff0c\u786e\u4fdd\u4f7f\u7528<code>removeEventListener<\/code>\u8fdb\u884c\u6e05\u7406\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528<code>bind()<\/code>\u6216\u7bad\u5934\u51fd\u6570\u6765\u7ed1\u5b9a\u6b63\u786e\u7684<code>this<\/code><\/strong>\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u9519\u8bef\u793a\u4f8b\uff1a\u5fd8\u8bb0\u79fb\u9664\u4e8b\u4ef6\u76d1\u542c\u5668\nconst button = document.getElementById('button');\nbutton.addEventListener('click', function() {\n  console.log('Clicked!');\n});\n\n\/\/ \u6b63\u786e\u793a\u4f8b\uff1a\u79fb\u9664\u4e8b\u4ef6\u76d1\u542c\u5668\nbutton.removeEventListener('click', function() {\n  console.log('Clicked!');\n});<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u8fd9\u4e9b\u8be6\u7ec6\u7684\u539f\u56e0\u5206\u6790\u548c\u89e3\u51b3\u65b9\u6848\uff0c\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u907f\u514d\u5e38\u89c1\u7684JavaScript\u9519\u8bef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728JavaScript\u5f00\u53d1\u4e2d\uff0c\u8bb8\u591a\u5e38\u89c1\u7684\u9519\u8bef\u95ee\u9898\u6e90\u4e8e\u57fa\u7840\u77e5\u8bc6\u7684\u4e0d\u8db3\u6216\u8bef\u7528\u3002\u672c\u6587\u5c06\u9488\u5bf9JavaScript\u5f00\u53d1\u4e2d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[],"class_list":["post-1427","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=1427"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1427\/revisions"}],"predecessor-version":[{"id":1428,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1427\/revisions\/1428"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=1427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=1427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=1427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}