{"id":158734,"date":"2024-05-08T12:56:23","date_gmt":"2024-05-08T04:56:23","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/158734.html"},"modified":"2024-05-08T12:56:27","modified_gmt":"2024-05-08T04:56:27","slug":"%e5%a6%82%e4%bd%95%e7%90%86%e8%a7%a3javascript%e7%9a%84%e5%87%bd%e6%95%b0%e5%85%b6%e5%ae%9e%e9%83%bd%e6%8c%87%e5%90%91%e6%9f%90%e4%b8%aa%e5%8f%98%e9%87%8f","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/158734.html","title":{"rendered":"\u5982\u4f55\u7406\u89e3JavaScript\u7684\u51fd\u6570\u5176\u5b9e\u90fd\u6307\u5411\u67d0\u4e2a\u53d8\u91cf"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26221234\/e0271e33-4acc-4104-84b5-6800853a9025.webp\" alt=\"\u5982\u4f55\u7406\u89e3JavaScript\u7684\u51fd\u6570\u5176\u5b9e\u90fd\u6307\u5411\u67d0\u4e2a\u53d8\u91cf\" \/><\/p>\n<p><p>\u5728JavaScript\u4e2d\uff0c\u51fd\u6570\u5176\u5b9e\u90fd\u88ab\u89c6\u4e3a\u5bf9\u8c61\uff0c\u56e0\u6b64\uff0c\u5b83\u4eec\u5b9e\u9645\u4e0a\u662f\u5bf9\u8c61\u5f15\u7528\u7c7b\u578b\u7684\u5b9e\u4f8b\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c<strong>JavaScript\u4e2d\u7684\u51fd\u6570\u90fd\u662f\u5bf9\u8c61\uff0c\u53ef\u4ee5\u50cf\u4efb\u4f55\u5176\u4ed6\u5bf9\u8c61\u4e00\u6837\u88ab\u8d4b\u503c\u7ed9\u4e00\u4e2a\u53d8\u91cf\u3001\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u6216\u8005\u4f5c\u4e3a\u5176\u4ed6\u51fd\u6570\u7684\u8fd4\u56de\u503c<\/strong>\u3002\u5f53\u58f0\u660e\u4e00\u4e2a\u51fd\u6570\u65f6\uff0c\u4f60\u5176\u5b9e\u662f\u521b\u5efa\u4e86\u4e00\u4e2a\u51fd\u6570\u5bf9\u8c61\uff0c\u5e76\u4e14\u5c06\u5b83\u8d4b\u503c\u7ed9\u4e86\u4e00\u4e2a\u53d8\u91cf\u3002\u4f8b\u5982\uff0c\u5f53\u4f60\u58f0\u660e <code>function myFunc() {}<\/code>\uff0c\u4f60\u521b\u5efa\u4e86\u4e00\u4e2a\u65b0\u7684\u51fd\u6570\u5bf9\u8c61\uff0c\u5e76\u4e14\u53d8\u91cf <code>myFunc<\/code> \u6307\u5411\u8fd9\u4e2a\u5bf9\u8c61\u3002\u8fd9\u610f\u5473\u7740\u51fd\u6570\u540d\u5b9e\u9645\u4e0a\u662f\u6307\u5411\u51fd\u6570\u5bf9\u8c61\u7684\u53d8\u91cf\u3002<\/p>\n<\/p>\n<p><p>\u8fd9\u4e2a\u7279\u6027\u8ba9\u51fd\u6570\u975e\u5e38\u7075\u6d3b\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5c06\u51fd\u6570\u8d4b\u503c\u7ed9\u53e6\u4e00\u4e2a\u53d8\u91cf\uff0c\u90a3\u4e48\u8fd9\u4e2a\u65b0\u7684\u53d8\u91cf\u4e5f\u6307\u5411\u4e86\u539f\u6709\u7684\u51fd\u6570\u5bf9\u8c61\u3002\u800c\u5f53\u901a\u8fc7\u8fd9\u4e2a\u65b0\u7684\u53d8\u91cf\u6765\u8c03\u7528\u51fd\u6570\u65f6\uff0c\u6267\u884c\u7684\u884c\u4e3a\u662f\u76f8\u540c\u7684\uff0c\u8fd9\u4e5f\u8bf4\u660e\u4e86\u51fd\u6570\u540d\u53ea\u662f\u5bf9\u51fd\u6570\u5bf9\u8c61\u7684\u5f15\u7528\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\u7684\u6587\u7ae0\u5185\u5bb9\u5c06\u8be6\u7ec6\u89e3\u91caJavaScript\u51fd\u6570\u4e0e\u53d8\u91cf\u7684\u5173\u7cfb\u4ee5\u53ca\u8fd9\u4e00\u7279\u6027\u5982\u4f55\u5f71\u54cdJavaScript\u7f16\u7a0b\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u51fd\u6570\u58f0\u660e\u4e0e\u51fd\u6570\u8868\u8fbe\u5f0f<\/h3>\n<\/p>\n<p><p>\u5728\u6df1\u5165\u4e86\u89e3JavaScript\u7684\u51fd\u6570\u4e0e\u53d8\u91cf\u7684\u5173\u7cfb\u4e4b\u524d\uff0c\u9700\u8981\u9996\u5148\u533a\u5206\u4e24\u79cd\u51fd\u6570\u521b\u5efa\u65b9\u5f0f\uff1a<strong>\u51fd\u6570\u58f0\u660e\u548c\u51fd\u6570\u8868\u8fbe\u5f0f<\/strong>\u3002<\/p>\n<\/p>\n<p><h4>\u51fd\u6570\u58f0\u660e<\/h4>\n<\/p>\n<p><p>\u51fd\u6570\u58f0\u660e\u662f\u4f7f\u7528 <code>function<\/code> \u5173\u952e\u8bcd\u8ddf\u968f\u4e00\u4e2a\u51fd\u6570\u540d\u79f0\u548c\u51fd\u6570\u4f53\u6765\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">function greet() {<\/p>\n<p>    console.log(&#039;Hello, world!&#039;);<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u51fd\u6570\u58f0\u660e\u4f1a\u88abJavaScript\u5f15\u64ce\u63d0\u524d\uff08\u5728\u4efb\u4f55\u4ee3\u7801\u6267\u884c\u4e4b\u524d\uff09\u6240\u8bc6\u522b\uff0c\u8fd9\u5c31\u610f\u5473\u7740\u5373\u4f7f\u51fd\u6570\u58f0\u660e\u5728\u8c03\u7528\u4e4b\u540e\u5b9a\u4e49\u4e5f\u53ef\u4ee5\u6b63\u5e38\u5de5\u4f5c\uff0c\u8fd9\u4e2a\u73b0\u8c61\u79f0\u4e3a\u201c\u51fd\u6570\u63d0\u5347\u201d\u3002<\/p>\n<\/p>\n<p><h4>\u51fd\u6570\u8868\u8fbe\u5f0f<\/h4>\n<\/p>\n<p><p>\u51fd\u6570\u8868\u8fbe\u5f0f\u5219\u662f\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u51fd\u6570\u5e76\u5c06\u5176\u8d4b\u503c\u7ed9\u4e00\u4e2a\u53d8\u91cf\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u51fd\u6570\u53ef\u4ee5\u662f\u533f\u540d\u7684\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">const sayHello = function() {<\/p>\n<p>    console.log(&#039;Hello!&#039;);<\/p>\n<p>};<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0d\u540c\u4e8e\u51fd\u6570\u58f0\u660e\uff0c\u51fd\u6570\u8868\u8fbe\u5f0f\u4e0d\u4f1a\u63d0\u5347\uff0c\u56e0\u6b64\u5728\u5b57\u9762\u91cf\u8d4b\u503c\u524d\uff0c\u65e0\u6cd5\u8c03\u7528\u5bf9\u5e94\u7684\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u51fd\u6570\u662f\u7b2c\u4e00\u7c7b\u5bf9\u8c61<\/h3>\n<\/p>\n<p><p>\u5728JavaScript\u4e2d\uff0c\u51fd\u6570\u662f\u201c\u4e00\u7b49\u516c\u6c11\u201d\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u53ef\u4ee5\u4f5c\u4e3a\u6570\u636e\u88ab\u4f20\u9012\u3002<strong>\u51fd\u6570\u53ef\u4ee5\u88ab\u5b58\u50a8\u5728\u53d8\u91cf\u3001\u6570\u7ec4\u6216\u5bf9\u8c61\u7684\u5c5e\u6027\u4e2d\uff1b\u53ef\u4ee5\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u5176\u4ed6\u51fd\u6570\uff1b\u4e5f\u53ef\u4ee5\u4ece\u5176\u4ed6\u51fd\u6570\u4e2d\u8fd4\u56de<\/strong>\u3002\u8fd9\u79cd\u7279\u6027\u6781\u5927\u63d0\u5347\u4e86JavaScript\u7684\u7f16\u7a0b\u7075\u6d3b\u6027\u3002<\/p>\n<\/p>\n<p><h4>\u5b58\u50a8\u5728\u53d8\u91cf\u4e2d<\/h4>\n<\/p>\n<p><p>\u5f53\u51fd\u6570\u88ab\u5b58\u50a8\u5728\u53d8\u91cf\u4e2d\u65f6\uff0c\u5b9e\u9645\u4e0a\u662f\u5c06\u51fd\u6570\u5bf9\u8c61\u7684\u5f15\u7528\u8d4b\u503c\u7ed9\u4e86\u90a3\u4e2a\u53d8\u91cf\uff0c\u4e4b\u540e\u53ef\u4ee5\u901a\u8fc7\u8be5\u53d8\u91cf\u6765\u8c03\u7528\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h4>\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012<\/h4>\n<\/p>\n<p><p>JavaScript\u5141\u8bb8\u5c06\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u5176\u4ed6\u51fd\u6570\u3002\u8fd9\u5728\u56de\u8c03\u6a21\u5f0f\u548c\u9ad8\u9636\u51fd\u6570\u4e2d\u975e\u5e38\u5e38\u89c1\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">function processUserInput(callback) {<\/p>\n<p>    const name = prompt(&#039;Please enter your name.&#039;);<\/p>\n<p>    callback(name);<\/p>\n<p>}<\/p>\n<p>processUserInput(greet);<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>greet<\/code> \u51fd\u6570\u88ab\u4f20\u9012\u7ed9\u4e86 <code>processUserInput<\/code> \u51fd\u6570\uff0c\u5e76\u4f5c\u4e3a\u56de\u8c03\u51fd\u6570\u88ab\u8c03\u7528\u3002<\/p>\n<\/p>\n<p><h4>\u4f5c\u4e3a\u5176\u4ed6\u51fd\u6570\u7684\u8fd4\u56de\u503c<\/h4>\n<\/p>\n<p><p>\u51fd\u6570\u4e5f\u53ef\u4ee5\u4ece\u5176\u4ed6\u51fd\u6570\u4e2d\u8fd4\u56de\uff0c\u8fd9\u5728\u521b\u5efa\u95ed\u5305\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">function makeMultiplier(multiplier) {<\/p>\n<p>    return function(x) {<\/p>\n<p>        return x * multiplier;<\/p>\n<p>    };<\/p>\n<p>}<\/p>\n<p>const double = makeMultiplier(2);<\/p>\n<p>console.log(double(5)); \/\/ \u8f93\u51fa10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>makeMultiplier<\/code> \u8fd4\u56de\u4e86\u4e00\u4e2a\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u5c06\u4f20\u5165\u7684\u503c\u4e58\u4ee5\u5728\u5916\u90e8\u51fd\u6570\u4e2d\u5b9a\u4e49\u7684\u500d\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u95ed\u5305\u548c\u4f5c\u7528\u57df<\/h3>\n<\/p>\n<p><p>\u95ed\u5305\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u5bf9\u8c61\uff0c\u5b83\u7ed3\u5408\u4e86\u4e00\u4e2a\u51fd\u6570\u548c\u8fd9\u4e2a\u51fd\u6570\u88ab\u521b\u5efa\u65f6\u6240\u5904\u7684\u8bcd\u6cd5\u73af\u5883\u7684\u6570\u636e\u3002<strong>\u95ed\u5305\u5141\u8bb8\u4e00\u4e2a\u51fd\u6570\u8bbf\u95ee\u5e76\u64cd\u4f5c\u5916\u90e8\u51fd\u6570\u4f5c\u7528\u57df\u4e2d\u7684\u53d8\u91cf<\/strong>\u3002<\/p>\n<\/p>\n<p><h4>\u95ed\u5305\u7684\u521b\u5efa<\/h4>\n<\/p>\n<p><p>\u5f53\u4e00\u4e2a\u51fd\u6570\u8fd4\u56de\u4e86\u53e6\u4e00\u4e2a\u51fd\u6570\u65f6\uff0c\u5c31\u521b\u5efa\u4e86\u4e00\u4e2a\u95ed\u5305\u3002\u5982\u524d\u9762 <code>makeMultiplier<\/code> \u7684\u4f8b\u5b50\u5c55\u793a\u7684\u90a3\u6837\uff0c\u8fd4\u56de\u7684\u51fd\u6570\u4f9d\u7136\u53ef\u4ee5\u8bbf\u95ee <code>multiplier<\/code> \u53d8\u91cf\uff0c\u5373\u4f7f\u5916\u90e8\u51fd\u6570\u5df2\u7ecf\u8fd4\u56de\u3002<\/p>\n<\/p>\n<p><h4>\u4f5c\u7528\u57df\u548c\u53d8\u91cf<\/h4>\n<\/p>\n<p><p>\u5728JavaScript\u4e2d\uff0c\u53d8\u91cf\u6839\u636e\u5176\u58f0\u660e\u4f4d\u7f6e\u7684\u4e0d\u540c\uff0c\u5177\u6709\u4e0d\u540c\u7684\u4f5c\u7528\u57df\u3002\u548c\u51fd\u6570\u76f8\u4f3c\uff0c\u5185\u90e8\u51fd\u6570\u4f1a\u6355\u6349\u5230\u5305\u542b\u5b83\u4eec\u7684\u5916\u90e8\u51fd\u6570\u7684\u4f5c\u7528\u57df\u3002\u5373\u4fbf\u5916\u90e8\u51fd\u6570\u5df2\u7ecf\u6267\u884c\u7ed3\u675f\uff0c\u5185\u90e8\u51fd\u6570\u4ecd\u7136\u53ef\u4ee5\u8bbf\u95ee\u5916\u90e8\u51fd\u6570\u4f5c\u7528\u57df\u4e2d\u7684\u53d8\u91cf\uff0c\u8fd9\u662f\u95ed\u5305\u7684\u7279\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5c06\u51fd\u6570\u8d4b\u503c\u7ed9\u53d8\u91cf\u7684\u6548\u679c<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u5c06\u51fd\u6570\u8d4b\u503c\u7ed9\u53d8\u91cf\uff0c\u6211\u4eec\u53ef\u4ee5\u6267\u884c\u4e00\u4e9b\u7075\u6d3b\u7684\u64cd\u4f5c\uff0c\u4f8b\u5982\u521b\u5efa\u51fd\u6570\u522b\u540d\u3001\u5728\u6570\u636e\u7ed3\u6784\u4e2d\u5b58\u50a8\u51fd\u6570\u6216\u8005\u6784\u5efa\u66f4\u590d\u6742\u7684\u62bd\u8c61\u3002<\/p>\n<\/p>\n<p><h4>\u521b\u5efa\u51fd\u6570\u522b\u540d<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7\u5c06\u4e00\u4e2a\u51fd\u6570\u8d4b\u503c\u7ed9\u53e6\u4e00\u4e2a\u53d8\u91cf\uff0c\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u4e3a\u51fd\u6570\u521b\u5efa\u522b\u540d\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">const originalFunction = function() {<\/p>\n<p>    console.log(&#039;I am the original function&#039;);<\/p>\n<p>};<\/p>\n<p>const functionAlias = originalFunction;<\/p>\n<p>functionAlias(); \/\/ \u8c03\u7528\u522b\u540d\uff0c\u8f93\u51fa &#039;I am the original function&#039;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5c55\u793a\u4e86\u51fd\u6570\u522b\u540d\u7684\u521b\u5efa\u8fc7\u7a0b\u3002<code>functionAlias<\/code> \u65b0\u53d8\u91cf\u4e0e <code>originalFunction<\/code> \u6307\u5411\u540c\u4e00\u4e2a\u51fd\u6570\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><h4>\u5728\u6570\u636e\u7ed3\u6784\u4e2d\u5b58\u50a8\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u51fd\u6570\u4f5c\u4e3a\u5bf9\u8c61\u53ef\u4ee5\u88ab\u5b58\u50a8\u5728\u6570\u7ec4\u6216\u5bf9\u8c61\u4e2d\uff0c\u8fd9\u6837\u53ef\u4ee5\u5728\u9700\u8981\u7684\u65f6\u5019\u901a\u8fc7\u5bf9\u5e94\u7684\u5f15\u7528\u6765\u8c03\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">const operations = {<\/p>\n<p>    multiply: function(a, b) {<\/p>\n<p>        return a * b;<\/p>\n<p>    },<\/p>\n<p>    add: function(a, b) {<\/p>\n<p>        return a + b;<\/p>\n<p>    }<\/p>\n<p>};<\/p>\n<p>console.log(operations.multiply(5, 5)); \/\/ \u8f93\u51fa 25<\/p>\n<p>console.log(operations.add(5, 5)); \/\/ \u8f93\u51fa 10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u4e24\u4e2a\u51fd\u6570\u88ab\u5b58\u50a8\u5728\u4e00\u4e2a\u5bf9\u8c61\u7684\u4e0d\u540c\u5c5e\u6027\u4e2d\uff0c\u4e4b\u540e\u53ef\u4ee5\u901a\u8fc7\u76f8\u5e94\u7684\u5c5e\u6027\u540d\u8c03\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u51fd\u6570\u5f15\u7528\u4e0ethis\u5173\u952e\u5b57<\/h3>\n<\/p>\n<p><p>\u5728JavaScript\u4e2d\uff0c\u51fd\u6570\u4e2d\u7684 <code>this<\/code> \u5173\u952e\u5b57\u662f\u4e00\u4e2a\u7279\u6b8a\u7684\u53d8\u91cf\uff0c\u5b83\u5728\u51fd\u6570\u8c03\u7528\u65f6\u786e\u5b9a\u5176\u503c\u3002<code>this<\/code> \u7684\u503c\u53d6\u51b3\u4e8e\u51fd\u6570\u662f\u5982\u4f55\u88ab\u8c03\u7528\u7684\uff0c\u800c\u4e0d\u662f\u5982\u4f55\u88ab\u5b9a\u4e49\u7684\u3002<\/p>\n<\/p>\n<p><h4>\u5168\u5c40\u4e0e\u5c40\u90e8\u51fd\u6570\u5f15\u7528<\/h4>\n<\/p>\n<p><p>\u5728\u5168\u5c40\u51fd\u6570\u6216\u5728\u5bf9\u8c61\u5916\u90e8\u5b9a\u4e49\u7684\u51fd\u6570\u4e2d\uff0c<code>this<\/code> \u901a\u5e38\u6307\u5411\u5168\u5c40\u5bf9\u8c61\uff08\u5728\u6d4f\u89c8\u5668\u4e2d\u662f <code>window<\/code> \u5bf9\u8c61\uff09\u3002\u5f53\u51fd\u6570\u4f5c\u4e3a\u5bf9\u8c61\u7684\u65b9\u6cd5\u88ab\u8c03\u7528\u65f6\uff0c<code>this<\/code> \u6307\u5411\u90a3\u4e2a\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">const person = {<\/p>\n<p>    name: &#039;Alice&#039;,<\/p>\n<p>    greet: function() {<\/p>\n<p>        console.log(`Hello, my name is ${this.name}`);<\/p>\n<p>    }<\/p>\n<p>};<\/p>\n<p>person.greet(); \/\/ \u8f93\u51fa &quot;Hello, my name is Alice&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>greet<\/code> \u51fd\u6570\u4f5c\u4e3a <code>person<\/code> \u5bf9\u8c61\u7684\u65b9\u6cd5\u88ab\u8c03\u7528\uff0c\u56e0\u6b64 <code>this<\/code> \u6307\u5411 <code>person<\/code> \u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><h4>\u901a\u8fc7call\u548capply\u4fee\u6539\u51fd\u6570\u5f15\u7528<\/h4>\n<\/p>\n<p><p>JavaScript \u5141\u8bb8\u901a\u8fc7 <code>call<\/code> \u548c <code>apply<\/code> \u65b9\u6cd5\u4fee\u6539\u51fd\u6570\u7684 <code>this<\/code> \u6307\u5411\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">function introduce(language) {<\/p>\n<p>    console.log(`I write ${language} code. My name is ${this.name}`);<\/p>\n<p>}<\/p>\n<p>const developer = {<\/p>\n<p>    name: &#039;Bob&#039;<\/p>\n<p>};<\/p>\n<p>introduce.call(developer, &#039;JavaScript&#039;); \/\/ \u8f93\u51fa \u201cI write JavaScript code. My name is Bob\u201d<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>introduce<\/code> \u51fd\u6570\u901a\u8fc7 <code>call<\/code> \u65b9\u6cd5\u88ab\u8c03\u7528\uff0c\u5e76\u4e14\u5176 <code>this<\/code> \u503c\u88ab\u6307\u5b9a\u4e3a <code>developer<\/code> \u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><p>\u7efc\u4e0a\u6240\u8ff0\uff0cJavaScript\u4e2d\u7684\u51fd\u6570\u662f\u5bf9\u8c61\uff0c\u8fd9\u8ba9\u51fd\u6570\u5728\u8bed\u8a00\u4e2d\u6709\u4e86\u975e\u5e38\u4e30\u5bcc\u7684\u7528\u9014\u548c\u7075\u6d3b\u6027\u3002\u51fd\u6570\u53ef\u4ee5\u88ab\u89c6\u4e3a\u53d8\u91cf\u6307\u5411\u7684\u503c\u7684\u4e00\u4e2a\u5b9e\u4f8b\uff0c\u80fd\u591f\u88ab\u5b58\u50a8\u3001\u4f20\u9012\u548c\u64cd\u4f5c\u3002\u4e86\u89e3\u8fd9\u4e9b\u7279\u6027\u5bf9\u4e8e\u638c\u63e1JavaScript\u7f16\u7a0b\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. JavaScript\u4e2d\u7684\u51fd\u6570\u662f\u5982\u4f55\u6307\u5411\u67d0\u4e2a\u53d8\u91cf\u7684\uff1f<\/strong><\/p>\n<p>JavaScript\u4e2d\u7684\u51fd\u6570\u5b9e\u9645\u4e0a\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u5bf9\u8c61\uff0c\u56e0\u6b64\u5b83\u4e5f\u53ef\u4ee5\u88ab\u8d4b\u503c\u7ed9\u4e00\u4e2a\u53d8\u91cf\u3002\u5f53\u5c06\u4e00\u4e2a\u51fd\u6570\u8d4b\u503c\u7ed9\u53d8\u91cf\u65f6\uff0c\u8be5\u53d8\u91cf\u5c31\u6307\u5411\u4e86\u8fd9\u4e2a\u51fd\u6570\u3002\u8fd9\u610f\u5473\u7740\u6211\u4eec\u53ef\u4ee5\u50cf\u64cd\u4f5c\u5176\u4ed6\u7c7b\u578b\u7684\u503c\u4e00\u6837\u6765\u64cd\u4f5c\u51fd\u6570\uff0c\u6bd4\u5982\u5c06\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u5176\u4ed6\u51fd\u6570\u3001\u5728\u5bf9\u8c61\u4e2d\u4f7f\u7528\u51fd\u6570\u4f5c\u4e3a\u5c5e\u6027\u503c\u7b49\u3002<\/p>\n<p><strong>2. \u5982\u4f55\u901a\u8fc7\u51fd\u6570\u5b9e\u73b0\u95ed\u5305\uff1f<\/strong><\/p>\n<p>\u95ed\u5305\u662f\u6307\u5728\u4e00\u4e2a\u51fd\u6570\u5185\u90e8\u521b\u5efa\u53e6\u4e00\u4e2a\u51fd\u6570\uff0c\u5e76\u4e14\u5185\u90e8\u51fd\u6570\u53ef\u4ee5\u8bbf\u95ee\u5916\u90e8\u51fd\u6570\u7684\u53d8\u91cf\u3002\u901a\u8fc7\u51fd\u6570\u5b9e\u73b0\u95ed\u5305\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5728JavaScript\u4e2d\u5b9e\u73b0\u4e00\u4e9b\u9ad8\u7ea7\u7684\u7f16\u7a0b\u6a21\u5f0f\uff0c\u6bd4\u5982\u6a21\u5757\u5316\u548c\u79c1\u6709\u53d8\u91cf\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u95ed\u5305\u6765\u9690\u85cf\u53d8\u91cf\uff0c\u53ea\u66b4\u9732\u51fa\u9700\u8981\u5bf9\u5916\u90e8\u53ef\u89c1\u7684\u63a5\u53e3\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u5b89\u5168\u6027\u3002<\/p>\n<p><strong>3. \u5982\u4f55\u7406\u89e3JavaScript\u4e2d\u7684\u7bad\u5934\u51fd\u6570\u548c\u666e\u901a\u51fd\u6570\u7684\u533a\u522b\uff1f<\/strong><\/p>\n<p>\u7bad\u5934\u51fd\u6570\u662fES6\u5f15\u5165\u7684\u4e00\u79cd\u65b0\u7684\u51fd\u6570\u8bed\u6cd5\uff0c\u5b83\u4e0e\u666e\u901a\u51fd\u6570\u5728\u8bed\u6cd5\u548c\u4f5c\u7528\u57df\u4e0a\u6709\u4e00\u4e9b\u4e0d\u540c\u3002\u4e0e\u666e\u901a\u51fd\u6570\u4e0d\u540c\uff0c\u7bad\u5934\u51fd\u6570\u6ca1\u6709\u81ea\u5df1\u7684this\u503c\uff0c\u5b83\u4f1a\u7ee7\u627f\u4e0a\u5c42\u4f5c\u7528\u57df\u7684this\u503c\u3002\u6b64\u5916\uff0c\u7bad\u5934\u51fd\u6570\u4e5f\u65e0\u6cd5\u88abnew\u5173\u952e\u5b57\u8c03\u7528\uff0c\u4e5f\u6ca1\u6709arguments\u5bf9\u8c61\u3002\u7bad\u5934\u51fd\u6570\u901a\u5e38\u7528\u4e8e\u7b80\u5316\u51fd\u6570\u7684\u5199\u6cd5\u548c\u5904\u7406this\u6307\u5411\u7684\u95ee\u9898\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u4e0d\u9002\u7528\uff0c\u9700\u8981\u4f7f\u7528\u666e\u901a\u51fd\u6570\u6765\u4ee3\u66ff\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728JavaScript\u4e2d\uff0c\u51fd\u6570\u5176\u5b9e\u90fd\u88ab\u89c6\u4e3a\u5bf9\u8c61\uff0c\u56e0\u6b64\uff0c\u5b83\u4eec\u5b9e\u9645\u4e0a\u662f\u5bf9\u8c61\u5f15\u7528\u7c7b\u578b\u7684\u5b9e\u4f8b\u3002\u6362\u53e5\u8bdd\u8bf4\uff0cJavaScr [&hellip;]","protected":false},"author":3,"featured_media":158739,"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\/158734"}],"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=158734"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/158734\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/158739"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=158734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=158734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=158734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}