{"id":167583,"date":"2024-05-08T16:05:49","date_gmt":"2024-05-08T08:05:49","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/167583.html"},"modified":"2024-05-08T16:05:53","modified_gmt":"2024-05-08T08:05:53","slug":"javascript%e5%bd%93%e6%96%b9%e6%b3%95%e5%8f%82%e6%95%b0%e7%b1%bb%e5%9e%8b%e4%b8%bafunction%e6%97%b6%e7%9a%84this%e6%8c%87%e5%90%91%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/167583.html","title":{"rendered":"Javascript\u5f53\u65b9\u6cd5\u53c2\u6570\u7c7b\u578b\u4e3afunction\u65f6\u7684this\u6307\u5411\u95ee\u9898"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27033453\/fc7125c4-4108-4d82-879a-aeb7ee154ee4.webp\" alt=\"Javascript\u5f53\u65b9\u6cd5\u53c2\u6570\u7c7b\u578b\u4e3afunction\u65f6\u7684this\u6307\u5411\u95ee\u9898\" \/><\/p>\n<p><p>JavaScript\u4e2d\u7684<code>this<\/code>\u6307\u5411\u901a\u5e38\u7531\u8c03\u7528\u4e0a\u4e0b\u6587\u51b3\u5b9a\uff0c\u4f8b\u5982\u5f53\u51fd\u6570\u4f5c\u4e3a\u5bf9\u8c61\u7684\u65b9\u6cd5\u88ab\u8c03\u7528\u65f6\uff0c<code>this<\/code>\u6307\u5411\u8be5\u5bf9\u8c61\uff1b\u5f53\u51fd\u6570\u88ab\u76f4\u63a5\u8c03\u7528\u65f6\uff0c<code>this<\/code>\u5728\u975e\u4e25\u683c\u6a21\u5f0f\u4e0b\u6307\u5411\u5168\u5c40\u5bf9\u8c61\u5982<code>window<\/code>\uff0c\u5728\u4e25\u683c\u6a21\u5f0f\u4e0b\u5219\u4e3a<code>undefined<\/code>\u3002\u5f53\u65b9\u6cd5\u53c2\u6570\u7c7b\u578b\u4e3a<code>function<\/code>\u65f6\uff0c<code>this<\/code>\u7684\u6307\u5411\u53d6\u51b3\u4e8e\u51fd\u6570\u662f\u5982\u4f55\u88ab\u4f20\u9012\u548c\u8c03\u7528\u7684\u3002\u5982\u679c\u56de\u8c03\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u53e6\u4e00\u4e2a\u51fd\u6570\uff0c\u5e76\u5728\u8be5\u51fd\u6570\u5185\u88ab\u76f4\u63a5\u8c03\u7528\uff0c\u90a3\u4e48<code>this<\/code>\u7684\u503c\u4f1a\u6839\u636e\u88ab\u8c03\u7528\u51fd\u6570\u7684\u65b9\u5f0f\u53d1\u751f\u53d8\u5316\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f7f\u7528<code>setTimeout<\/code>\u6216\u8005\u6570\u7ec4\u7684<code>.forEach<\/code>\u65b9\u6cd5\uff0c<code>this<\/code>\u901a\u5e38\u4f1a\u88ab\u8bbe\u7f6e\u4e3a<code>window<\/code>\u6216\u76f8\u5e94\u7684\u5bf9\u8c61\u3002\u7136\u800c\uff0c\u82e5\u60f3\u4fdd\u6301\u539f\u59cb\u7684<code>this<\/code>\u4e0a\u4e0b\u6587\uff0c\u53ef\u4ee5\u4f7f\u7528<code>.bind<\/code>\u65b9\u6cd5\u663e\u5f0f\u7ed1\u5b9a\uff0c\u6216\u8005\u4f7f\u7528\u7bad\u5934\u51fd\u6570\u6355\u83b7\u58f0\u660e\u65f6\u6240\u5728\u4e0a\u4e0b\u6587\u7684<code>this<\/code>\u503c\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001THIS\u5728JavaScript\u4e2d\u7684\u5de5\u4f5c\u539f\u7406<\/h2>\n<\/p>\n<p><p>JavaScript\u7684<code>this<\/code>\u5173\u952e\u5b57\u662f\u52a8\u6001\u7684\uff0c\u5b83\u6307\u5411\u51fd\u6570\u8c03\u7528\u65f6\u7684\u4e0a\u4e0b\u6587\u5bf9\u8c61\u3002\u4e86\u89e3\u8fd9\u4e00\u70b9\u5bf9\u4e8e\u7406\u89e3\u53c2\u6570\u7c7b\u578b\u4e3a<code>function<\/code>\u65f6<code>this<\/code>\u6307\u5411\u7684\u95ee\u9898\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<\/p>\n<p><h3>\u51fd\u6570\u4f5c\u4e3a\u65b9\u6cd5\u8c03\u7528<\/h3>\n<\/p>\n<p><p>\u5f53\u51fd\u6570\u4f5c\u4e3a\u5bf9\u8c61\u7684\u65b9\u6cd5\u88ab\u8c03\u7528\u65f6\uff0c<code>this<\/code>\u6307\u5411\u8be5\u5bf9\u8c61\u672c\u8eab\u3002\u4f8b\u5982\uff0c\u5f53\u6211\u4eec\u6709\u4e00\u4e2a\u5bf9\u8c61\u548c\u8be5\u5bf9\u8c61\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">var person = {<\/p>\n<p>  name: &#039;Alice&#039;,<\/p>\n<p>  greet: function() {<\/p>\n<p>    console.log(&#039;Hi, I am &#039; + this.name);<\/p>\n<p>  }<\/p>\n<p>};<\/p>\n<p>person.greet();  \/\/ Hi, I am Alice<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c<code>greet<\/code>\u65b9\u6cd5\u5185\u90e8\u7684<code>this<\/code>\u6307\u5411<code>person<\/code>\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><h3>\u51fd\u6570\u4f5c\u4e3a\u666e\u901a\u51fd\u6570\u8c03\u7528<\/h3>\n<\/p>\n<p><p>\u5f53\u51fd\u6570\u4e0d\u4f5c\u4e3a\u5bf9\u8c61\u7684\u5c5e\u6027\u88ab\u8c03\u7528\u65f6\uff0c<code>this<\/code>\u7684\u503c\u53d6\u51b3\u4e8e\u4e25\u683c\u6a21\u5f0f\u4e0e\u975e\u4e25\u683c\u6a21\u5f0f\u3002\u5728\u4e25\u683c\u6a21\u5f0f\u4e0b\uff0c<code>this<\/code>\u4f1a\u662f<code>undefined<\/code>\uff1b\u5728\u975e\u4e25\u683c\u6a21\u5f0f\u4e0b\uff0c\u5b83\u4f1a\u6307\u5411\u5168\u5c40\u5bf9\u8c61\uff0c\u901a\u5e38\u662f<code>window<\/code>\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">function show() {<\/p>\n<p>  console.log(&#039;This is: &#039;, this);<\/p>\n<p>}<\/p>\n<p>show(); \/\/ \u5728\u6d4f\u89c8\u5668\u4e2d\uff0cthis \u6307\u5411window<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u6784\u9020\u51fd\u6570\u8c03\u7528\u65f6\u7684THIS<\/h3>\n<\/p>\n<p><p>\u5f53\u4f7f\u7528<code>new<\/code>\u5173\u952e\u5b57\u8c03\u7528\u6784\u9020\u51fd\u6570\u65f6\uff0c<code>this<\/code>\u4f1a\u6307\u5411\u65b0\u521b\u5efa\u7684\u5bf9\u8c61\u5b9e\u4f8b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">function Person(name) {<\/p>\n<p>  this.name = name;<\/p>\n<p>}<\/p>\n<p>var person = new Person(&#039;Alice&#039;);<\/p>\n<p>console.log(person.name);  \/\/ Alice<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c<code>this<\/code>\u6307\u5411\u901a\u8fc7\u6784\u9020\u51fd\u6570\u521b\u5efa\u7684\u65b0\u5b9e\u4f8b<code>person<\/code>\u3002<\/p>\n<\/p>\n<p><h3>DOM\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u4e2d\u7684THIS<\/h3>\n<\/p>\n<p><p>\u5728DOM\u4e8b\u4ef6\u76d1\u542c\u51fd\u6570\u4e2d\uff0c<code>this<\/code>\u901a\u5e38\u6307\u5411\u89e6\u53d1\u4e8b\u4ef6\u7684\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">button.addEventListener(&#039;click&#039;, function() {<\/p>\n<p>  console.log(this);  \/\/ \u6307\u5411\u89e6\u53d1\u4e8b\u4ef6\u7684button\u5143\u7d20<\/p>\n<p>});<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e8c\u3001\u5c06\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u65f6\u7684THIS\u6307\u5411<\/h2>\n<\/p>\n<p><p>\u5f53\u4f60\u5c06\u4e00\u4e2a\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u53e6\u4e00\u4e2a\u51fd\u6570\u65f6\uff0c\u88ab\u4f20\u9012\u7684\u51fd\u6570\uff08\u5373\u56de\u8c03\u51fd\u6570\uff09\u7684<code>this<\/code>\u503c\u5c06\u5931\u53bb\u539f\u6709\u4e0a\u4e0b\u6587\u3002<\/p>\n<\/p>\n<p><h3>\u76f4\u63a5\u8c03\u7528\u56de\u8c03\u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u4f60\u76f4\u63a5\u8c03\u7528\u4e00\u4e2a\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7684\u51fd\u6570\uff0c<code>this<\/code>\u6307\u5411\u4f1a\u53d8\u4e3a\u5168\u5c40\u5bf9\u8c61\u6216\u8005<code>undefined<\/code>\uff08\u4e25\u683c\u6a21\u5f0f\u4e0b\uff09\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">function outerFunction(callback) {<\/p>\n<p>  callback();<\/p>\n<p>}<\/p>\n<p>var myObject = {<\/p>\n<p>  method: function() {<\/p>\n<p>    outerFunction(this.actualMethod);<\/p>\n<p>  },<\/p>\n<p>  actualMethod: function() {<\/p>\n<p>    console.log(this);  \/\/ \u5728\u975e\u4e25\u683c\u6a21\u5f0f\u4e0b\uff0cthis \u6307\u5411 window\uff1b\u5728\u4e25\u683c\u6a21\u5f0f\u4e0b\uff0cthis \u662f undefined<\/p>\n<p>  }<\/p>\n<p>};<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4f7f\u7528CALL\u548cAPPLY\u4fdd\u6301THIS\u4e0a\u4e0b\u6587<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528<code>.call<\/code>\u6216\u8005<code>.apply<\/code>\u65b9\u6cd5\u53ef\u4ee5\u6307\u5b9a\u56de\u8c03\u51fd\u6570\u7684<code>this<\/code>\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">function outerFunction(callback) {<\/p>\n<p>  callback.call(this);<\/p>\n<p>}<\/p>\n<p>myObject.method = function() {<\/p>\n<p>  outerFunction(this.actualMethod);<\/p>\n<p>};<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4f8b\u5b50\u4e2d\uff0c\u4f7f\u7528<code>.call(this)<\/code>\u786e\u4fdd\u4e86<code>actualMethod<\/code>\u6267\u884c\u65f6\u5185\u90e8\u7684<code>this<\/code>\u4ecd\u7136\u6307\u5411<code>myObject<\/code>\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u5982\u4f55\u7ef4\u6301\u6b63\u786e\u7684THIS\u6307\u5411<\/h2>\n<\/p>\n<p><p>\u5728JavaScript\u4e2d\uff0c\u4fdd\u6301\u6b63\u786e\u7684<code>this<\/code>\u6307\u5411\u662f\u975e\u5e38\u5e38\u89c1\u7684\u9700\u6c42\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>BIND\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p><code>.bind<\/code>\u65b9\u6cd5\u521b\u5efa\u4e00\u4e2a\u65b0\u51fd\u6570\uff0c\u5f53\u88ab\u8c03\u7528\u65f6\uff0c\u5b83\u7684<code>this<\/code>\u8bbe\u5b9a\u4e3a\u63d0\u4f9b\u7684\u503c\uff0c\u4ece\u800c\u53ef\u4ee5\u786e\u4fdd\u65e0\u8bba\u4f55\u65f6\u4f55\u5730\u8c03\u7528\u51fd\u6570\uff0c<code>this<\/code>\u603b\u662f\u6b63\u786e\u7684\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">function outerFunction(callback) {<\/p>\n<p>  \/\/ ...<\/p>\n<p>}<\/p>\n<p>myObject.method = function() {<\/p>\n<p>  outerFunction(this.actualMethod.bind(this));<\/p>\n<p>};<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528<code>.bind(this)<\/code>\u53ef\u4ee5\u5728\u4efb\u4f55\u65f6\u5019\u8c03\u7528<code>actualMethod<\/code>\u65f6\u90fd\u4fdd\u8bc1<code>this<\/code>\u6307\u5411<code>myObject<\/code>\u3002<\/p>\n<\/p>\n<p><h3>\u7bad\u5934\u51fd\u6570\u7ef4\u6301THIS\u4e0a\u4e0b\u6587<\/h3>\n<\/p>\n<p><p>\u7bad\u5934\u51fd\u6570\u4e0d\u7ed1\u5b9a\u81ea\u5df1\u7684<code>this<\/code>\uff0c\u5b83\u4eec\u6355\u83b7\u5176\u6240\u5728\u4e0a\u4e0b\u6587\u7684<code>this<\/code>\u503c\u4f5c\u4e3a\u81ea\u5df1\u7684<code>this<\/code>\u503c\uff0c\u8fd9\u4f7f\u5f97\u7bad\u5934\u51fd\u6570\u6210\u4e3a\u7ef4\u6301<code>this<\/code>\u6307\u5411\u7684\u4fbf\u5229\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">myObject.method = function() {<\/p>\n<p>  outerFunction(() =&gt; {<\/p>\n<p>    console.log(this);  \/\/ \u7bad\u5934\u51fd\u6570\u6ca1\u6709\u81ea\u5df1\u7684 this\uff0c\u6240\u4ee5 this \u6307\u5411 method \u88ab\u8c03\u7528\u65f6\u7684 myObject<\/p>\n<p>  });<\/p>\n<p>};<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u6b64\uff0c\u65e0\u8bba\u4f55\u65f6\u8c03\u7528\u4f20\u9012\u7ed9<code>outerFunction<\/code>\u7684\u7bad\u5934\u51fd\u6570\uff0c<code>this<\/code>\u603b\u662f\u6307\u5411<code>myObject<\/code>\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001THIS\u9677\u9631\u548c\u5e38\u89c1\u8bef\u533a<\/h2>\n<\/p>\n<p><p><code>this<\/code>\u53ef\u4ee5\u662fJavaScript\u7f16\u7a0b\u4e2d\u6700\u5bb9\u6613\u6df7\u6dc6\u7684\u6982\u5ff5\u4e4b\u4e00\uff0c\u5c24\u5176\u662f\u5bf9\u4e8e\u65b0\u624b\u5f00\u53d1\u8005\u6765\u8bf4\u3002\u7406\u89e3\u5176\u5de5\u4f5c\u539f\u7406\u4ee5\u53ca\u5982\u4f55\u907f\u514d\u5e38\u89c1\u7684\u9677\u9631\u662f\u5f88\u91cd\u8981\u7684\u3002<\/p>\n<\/p>\n<p><h3>\u56de\u8c03\u51fd\u6570\u4e2d\u7684THIS<\/h3>\n<\/p>\n<p><p>\u5728\u56de\u8c03\u51fd\u6570\u4e2d\uff0c\u5982<code>setTimeout<\/code>\u6216\u8005\u6570\u7ec4\u7684<code>.forEach<\/code>\u65b9\u6cd5\uff0c<code>this<\/code>\u7684\u503c\u548c\u4f60\u53ef\u80fd\u671f\u671b\u7684\u4e0d\u540c\uff0c\u8fd9\u662f\u56e0\u4e3a\u8fd9\u4e9b\u51fd\u6570\u7684\u8c03\u7528\u662f\u5728\u53e6\u4e00\u4e2a\u4e0a\u4e0b\u6587\u4e2d\u5b8c\u6210\u7684\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">myObject.method = function() {<\/p>\n<p>  setTimeout(this.actualMethod, 1000);<\/p>\n<p>  \/\/ `setTimeout`\u4e2d\u7684 this.actualMethod \u8c03\u7528\u4f1a\u4e22\u5931 myObject \u4e0a\u4e0b\u6587<\/p>\n<p>};<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u5230\u65f6\u95f4\u540e\u6267\u884c\u7684<code>this.actualMethod<\/code>\u4f1a\u4e22\u5931\u5bf9<code>myObject<\/code>\u7684\u5f15\u7528\uff0c\u56e0\u4e3a\u5b83\u88ab\u4f5c\u4e3a\u4e00\u4e2a\u672a\u7ed1\u5b9a<code>this<\/code>\u7684\u51fd\u6570\u4f20\u9012\u7ed9\u4e86<code>setTimeout<\/code>\u3002<\/p>\n<\/p>\n<p><h3>\u6784\u9020\u51fd\u6570\u548cCLASS\u4e2d\u7684THIS<\/h3>\n<\/p>\n<p><p>\u8bb0\u4f4f\uff0c\u5728\u4f7f\u7528\u6784\u9020\u51fd\u6570\u6216\u7c7b\u65f6\uff0c<code>this<\/code>\u603b\u662f\u6307\u5411\u65b0\u521b\u5efa\u7684\u5b9e\u4f8b\u5bf9\u8c61\u3002\u8fd9\u901a\u5e38\u662f\u671f\u671b\u7684\u884c\u4e3a\uff0c\u4f46\u5982\u679c\u5728\u65b9\u6cd5\u5185\u90e8\u4f7f\u7528\u4e86\u5916\u90e8\u5b9a\u4e49\u7684\u51fd\u6570\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u624b\u52a8\u7ed1\u5b9a<code>this<\/code>\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">function Person() {<\/p>\n<p>  this.age = 0;<\/p>\n<p>  setInterval(function growUp() {<\/p>\n<p>    \/\/ \u8fd9\u91cc\u7684 this \u4e0d\u6307\u5411 Person \u5b9e\u4f8b<\/p>\n<p>    this.age++;<\/p>\n<p>  }, 1000);<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u4f60\u53ef\u4ee5\u5728<code>setInterval<\/code>\u8c03\u7528\u4e2d\u4f7f\u7528\u7bad\u5934\u51fd\u6570\uff0c\u6216\u8005\u5728<code>growUp<\/code>\u51fd\u6570\u5916\u90e8\u4f7f\u7528<code>.bind(this)<\/code>\u3002<\/p>\n<\/p>\n<p><p>JavaScript\u7684<code>this<\/code>\u6982\u5ff5\u53ca\u5176\u6307\u5411\u662f\u4efb\u4f55\u5f00\u53d1\u4eba\u5458\u90fd\u5fc5\u987b\u638c\u63e1\u7684\u91cd\u8981\u90e8\u5206\u3002\u5bf9\u4e8e\u51fd\u6570\u53c2\u6570\u7c7b\u578b\u4e3a<code>function<\/code>\u7684\u60c5\u51b5\uff0c\u660e\u786e\u5176\u8c03\u7528\u65b9\u5f0f\u548c\u4e0a\u4e0b\u6587\u73af\u5883\u662f\u89e3\u51b3<code>this<\/code>\u6307\u5411\u95ee\u9898\u7684\u5173\u952e\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. JavaScript\u4e2d\u5f53\u65b9\u6cd5\u53c2\u6570\u7c7b\u578b\u4e3afunction\u65f6\uff0cthis\u6307\u5411\u95ee\u9898\u5982\u4f55\u89e3\u51b3\uff1f<\/strong><\/p>\n<p>\u5f53\u65b9\u6cd5\u53c2\u6570\u7c7b\u578b\u4e3a\u51fd\u6570\u65f6\uff0cJavaScript\u4e2d\u7684this\u6307\u5411\u4f1a\u53d1\u751f\u53d8\u5316\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528bind()\u65b9\u6cd5\u6765\u6307\u5b9a\u51fd\u6570\u5185\u90e8\u7684this\u6307\u5411\u3002\u901a\u8fc7bind()\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c06\u51fd\u6570\u7ed1\u5b9a\u5230\u6307\u5b9a\u7684\u5bf9\u8c61\u4e0a\uff0c\u4f7f\u5176\u5185\u90e8\u7684this\u6307\u5411\u8be5\u5bf9\u8c61\u3002<\/p>\n<p><strong>2. \u4ec0\u4e48\u60c5\u51b5\u4e0b\u4f1a\u51fa\u73b0JavaScript\u65b9\u6cd5\u53c2\u6570\u7c7b\u578b\u4e3a\u51fd\u6570\u65f6this\u6307\u5411\u95ee\u9898\uff1f<\/strong><\/p>\n<p>\u5f53\u5c06\u4e00\u4e2a\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u53e6\u4e00\u4e2a\u51fd\u6570\u5e76\u5728\u5176\u4e2d\u8c03\u7528\u65f6\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0JavaScript\u65b9\u6cd5\u53c2\u6570\u7c7b\u578b\u4e3a\u51fd\u6570\u65f6\u7684this\u6307\u5411\u95ee\u9898\u3002\u8fd9\u662f\u56e0\u4e3a\u5728\u51fd\u6570\u5185\u90e8\u8c03\u7528\u65f6\uff0cthis\u7684\u503c\u53d6\u51b3\u4e8e\u8c03\u7528\u51fd\u6570\u7684\u65b9\u5f0f\u548c\u4e0a\u4e0b\u6587\u3002<\/p>\n<p><strong>3. \u9664\u4e86\u4f7f\u7528bind()\u65b9\u6cd5\uff0c\u8fd8\u6709\u5176\u4ed6\u89e3\u51b3JavaScript\u65b9\u6cd5\u53c2\u6570\u7c7b\u578b\u4e3a\u51fd\u6570\u65f6this\u6307\u5411\u95ee\u9898\u7684\u65b9\u6cd5\u5417\uff1f<\/strong><\/p>\n<p>\u9664\u4e86\u4f7f\u7528bind()\u65b9\u6cd5\u6765\u89e3\u51b3JavaScript\u65b9\u6cd5\u53c2\u6570\u7c7b\u578b\u4e3a\u51fd\u6570\u65f6\u7684this\u6307\u5411\u95ee\u9898\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u7bad\u5934\u51fd\u6570\u6765\u89e3\u51b3\u8be5\u95ee\u9898\u3002\u7bad\u5934\u51fd\u6570\u4e0d\u4f1a\u521b\u5efa\u81ea\u5df1\u7684this\uff0c\u800c\u662f\u4f1a\u6355\u83b7\u5176\u6240\u5728\u4e0a\u4e0b\u6587\u7684this\u503c\u3002\u8fd9\u610f\u5473\u7740\u5728\u7bad\u5934\u51fd\u6570\u5185\u90e8\uff0cthis\u6307\u5411\u5916\u5c42\u51fd\u6570\u7684this\u503c\uff0c\u800c\u4e0d\u662f\u8c03\u7528\u7bad\u5934\u51fd\u6570\u7684\u65b9\u5f0f\u6216\u4e0a\u4e0b\u6587\u51b3\u5b9a\u3002\u56e0\u6b64\uff0c\u4f7f\u7528\u7bad\u5934\u51fd\u6570\u53ef\u4ee5\u907f\u514d\u8be5\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"JavaScript\u4e2d\u7684this\u6307\u5411\u901a\u5e38\u7531\u8c03\u7528\u4e0a\u4e0b\u6587\u51b3\u5b9a\uff0c\u4f8b\u5982\u5f53\u51fd\u6570\u4f5c\u4e3a\u5bf9\u8c61\u7684\u65b9\u6cd5\u88ab\u8c03\u7528\u65f6\uff0cthis\u6307\u5411\u8be5\u5bf9\u8c61 [&hellip;]","protected":false},"author":3,"featured_media":167587,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/167583"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=167583"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/167583\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/167587"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=167583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=167583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=167583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}