{"id":52626,"date":"2024-12-03T08:22:24","date_gmt":"2024-12-03T00:22:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52626\/"},"modified":"2024-12-03T08:22:24","modified_gmt":"2024-12-03T00:22:24","slug":"%e4%ba%86%e8%a7%a3-javascript-%e4%b8%ad%e7%9a%84%e4%bd%9c%e7%94%a8%e5%9f%9f%e5%92%8c%e4%bd%9c%e7%94%a8%e5%9f%9f%e9%93%be-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52626\/","title":{"rendered":"\u4e86\u89e3 JavaScript \u4e2d\u7684\u4f5c\u7528\u57df\u548c\u4f5c\u7528\u57df\u94fe"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u4e86\u89e3 JavaScript \u4e2d\u7684\u4f5c\u7528\u57df\u548c\u4f5c\u7528\u57df\u94fe<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span>    <\/p>\n<p>\u76ee\u524d\u7c73\u4e91\u4e0a\u5df2\u7ecf\u6709\u5f88\u591a\u5173\u4e8e<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u7684\u6587\u7ae0\u4e86\uff0c\u81ea\u5df1\u5728\u521d\u6b21\u9605\u8bfb\u8fd9\u4e9b\u6587\u7ae0\u4e2d\uff0c\u4e5f\u89c1\u8bc6\u5230\u4e86\u5f88\u591a\u5b66\u4e60\u601d\u8def\uff1b\u90a3\u4e48\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u4e86\u89e3 JavaScript \u4e2d\u7684\u4f5c\u7528\u57df\u548c\u4f5c\u7528\u57df\u94fe\u300b<\/span>\uff0c\u4e5f\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff0c\u5982\u679c\u9605\u8bfb\u5b8c\u540e\u771f\u7684\u5bf9\u4f60\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u6709\u5e2e\u52a9\uff0c\u6b22\u8fce\u52a8\u52a8\u624b\u6307\uff0c\u8bc4\u8bba\u7559\u8a00\u5e76\u5206\u4eab~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241122\/1732240311673fe3b7c98e5.jpg\" class=\"aligncenter\" title=\"\u4e86\u89e3 JavaScript \u4e2d\u7684\u4f5c\u7528\u57df\u548c\u4f5c\u7528\u57df\u94fe\u63d2\u56fe\" alt=\"\u4e86\u89e3 JavaScript \u4e2d\u7684\u4f5c\u7528\u57df\u548c\u4f5c\u7528\u57df\u94fe\u63d2\u56fe\" \/><\/p>\n<p>javascript \u5f00\u53d1\u4eba\u5458\u7ecf\u5e38\u4f1a\u9047\u5230\u4f5c\u7528\u57df\u3001\u4f5c\u7528\u57df\u94fe\u3001\u8bcd\u6cd5\u73af\u5883\u548c\u4e0d\u540c\u7c7b\u578b\u7684\u4f5c\u7528\u57df\uff08\u5168\u5c40\u4f5c\u7528\u57df\u3001\u51fd\u6570\u4f5c\u7528\u57df\u548c\u5c40\u90e8\u4f5c\u7528\u57df\uff09\u7b49\u672f\u8bed\u3002\u8fd9\u4e9b\u6982\u5ff5\u5bf9\u4e8e\u7406\u89e3\u53d8\u91cf\u548c\u51fd\u6570\u7684\u884c\u4e3a\u65b9\u5f0f\u3001\u5b83\u4eec\u7684\u53ef\u8bbf\u95ee\u6027\u4ee5\u53ca javascript \u5728\u6267\u884c\u4ee3\u7801\u65f6\u5982\u4f55\u627e\u5230\u5b83\u4eec\u81f3\u5173\u91cd\u8981\u3002\u5728\u672c\u535a\u5ba2\u4e2d\uff0c\u6211\u4eec\u5c06\u5206\u89e3\u8fd9\u4e9b\u4e3b\u9898\uff0c\u4ee5\u5e2e\u52a9\u60a8\u638c\u63e1 javascript \u4e2d\u7684\u4f5c\u7528\u57df\u548c\u4f5c\u7528\u57df\u94fe\u3002<\/p>\n<p><strong>1\u3002\u4ec0\u4e48\u662f\u8303\u56f4\uff1f<\/strong><\/p>\n<p>\u5728 javascript \u4e2d\uff0c\u4f5c\u7528\u57df\u5b9a\u4e49\u4e86\u53d8\u91cf\u548c\u51fd\u6570\u7684\u53ef\u8bbf\u95ee\u6027\u6216\u53ef\u89c1\u6027\u3002\u5b83\u51b3\u5b9a\u53d8\u91cf\u5728\u54ea\u91cc\u53ef\u7528\u4ee5\u53ca\u5728\u54ea\u91cc\u4e0d\u53ef\u7528\u3002\u4f8b\u5982\uff0c\u5728\u4e00\u4e2a\u51fd\u6570\u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf\u53ef\u80fd\u65e0\u6cd5\u5728\u53e6\u4e00\u51fd\u6570\u4e2d\u6216\u5168\u5c40\u8bbf\u95ee\u3002 javascript \u6709\u51e0\u79cd\u7c7b\u578b\u7684\u4f5c\u7528\u57df\uff0c\u60a8\u5e94\u8be5\u6ce8\u610f\uff1a<\/p>\n<ul>\n<li>\u5168\u7403\u8303\u56f4<\/li>\n<li>\u529f\u80fd\u8303\u56f4<\/li>\n<li>\u5757\/\u672c\u5730\u8303\u56f4<\/li>\n<\/ul>\n<p>\u4e86\u89e3\u8fd9\u4e9b\u4e0d\u540c\u7c7b\u578b\u7684\u4f5c\u7528\u57df\u53ef\u4ee5\u5e2e\u52a9\u60a8\u7f16\u5199\u9ad8\u6548\u4e14\u65e0\u9519\u8bef\u7684\u4ee3\u7801\u3002<\/p>\n<p><strong>2\u3002\u8bcd\u6c47\u73af\u5883<\/strong><\/p>\n<p>\u5728\u6df1\u5165\u7814\u7a76\u4e0d\u540c\u7c7b\u578b\u7684\u8303\u56f4\u4e4b\u524d\uff0c\u4e86\u89e3\u8bcd\u6cd5\u73af\u5883\u975e\u5e38\u91cd\u8981\u3002\u6bcf\u6b21\u8fd0\u884c javascript \u4ee3\u7801\u65f6\uff0c\u5b83\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u8bcd\u6cd5\u73af\u5883\u6765\u7ba1\u7406\u4ee3\u7801\u7279\u5b9a\u90e8\u5206\u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf\u548c\u51fd\u6570\u3002\u8bcd\u6c47\u73af\u5883\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u73af\u5883\u8bb0\u5f55 \u2013 \u5b58\u50a8\u8303\u56f4\u5185\u7684\u53d8\u91cf\u548c\u51fd\u6570\u3002<\/li>\n<li>\u5bf9\u5916\u90e8\u73af\u5883\u7684\u5f15\u7528 \u2013 \u4fdd\u6301\u4e0e\u5916\u90e8\u8bcd\u6cd5\u73af\u5883\uff08\u901a\u5e38\u79f0\u4e3a\u7236\u73af\u5883\uff09\u7684\u94fe\u63a5\uff0c\u8fd9\u5141\u8bb8\u8303\u56f4\u94fe\u3002<\/li>\n<\/ul>\n<p>javascript \u4f7f\u7528\u8bcd\u6cd5\u73af\u5883\u6839\u636e\u4ee3\u7801\u7f16\u5199\u4f4d\u7f6e\uff08\u4e0d\u4e00\u5b9a\u662f\u6267\u884c\u4f4d\u7f6e\uff09\u6765\u786e\u5b9a\u53d8\u91cf\u7684\u53ef\u8bbf\u95ee\u6027\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u79f0\u4e3a\u8bcd\u6cd5\u4f5c\u7528\u57df\u3002<\/p>\n<p><strong>3\u3002 javascript \u4e2d\u7684\u4f5c\u7528\u57df\u7c7b\u578b<\/strong><\/p>\n<p><strong>a) \u5168\u7403\u8303\u56f4<\/strong><\/p>\n<p>\u5168\u5c40\u8303\u56f4\u610f\u5473\u7740\u53d8\u91cf\u6216\u51fd\u6570\u662f\u5728\u6700\u5916\u5c42\u4e0a\u4e0b\u6587\u4e2d\u5b9a\u4e49\u7684\uff08\u5373\u4e0d\u5728\u51fd\u6570\u6216\u5757\u5185\uff09\u3002\u5728\u5168\u5c40\u8303\u56f4\u5185\u5b9a\u4e49\u7684\u53d8\u91cf\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u7684\u4efb\u4f55\u4f4d\u7f6e\u8bbf\u95ee\u3002<\/p>\n<pre>let globalvar = \"i'm global!\";\n\nfunction printglobalvar() {\n    console.log(globalvar); \/\/ accessible here\n}\n\nprintglobalvar(); \/\/ output: i'm global\nconsole.log(globalvar); \/\/ also accessible here\n\n<\/pre>\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0cglobalvar \u662f\u5728\u5168\u5c40\u8303\u56f4\u5185\u5b9a\u4e49\u7684\uff0c\u4f7f\u5176\u53ef\u4ee5\u5728 printglobalvar \u51fd\u6570\u5185\u90e8\u548c\u5916\u90e8\u8bbf\u95ee\u3002<\/p>\n<p><strong>b) \u529f\u80fd\u8303\u56f4<\/strong><\/p>\n<p>javascript \u5177\u6709\u51fd\u6570\u4f5c\u7528\u57df\uff0c\u8fd9\u610f\u5473\u7740\u5728\u51fd\u6570\u5185\u90e8\u4f7f\u7528 var\u3001let \u6216 const \u58f0\u660e\u7684\u53d8\u91cf\u5728\u8be5\u51fd\u6570\u5916\u90e8\u65e0\u6cd5\u8bbf\u95ee\u3002\u51fd\u6570\u521b\u5efa\u81ea\u5df1\u7684\u4f5c\u7528\u57df\u5e76\u9650\u5236\u5176\u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf\u3002<\/p>\n<pre>function myfunction() {\n    let localvar = \"i'm local!\";\n    console.log(localvar); \/\/ output: i'm local!\n}\n\nmyfunction();\nconsole.log(localvar); \/\/ error: localvar is not defined\n\n<\/pre>\n<p>\u8fd9\u91cc\uff0clocalvar \u662f\u5728 myfunction \u5185\u90e8\u5b9a\u4e49\u7684\uff0c\u65e0\u6cd5\u5728\u5176\u5916\u90e8\u8bbf\u95ee\uff0c\u5c55\u793a\u4e86\u51fd\u6570\u4f5c\u7528\u57df\u3002<\/p>\n<p><strong>c) \u5757\u4f5c\u7528\u57df\uff08\u5c40\u90e8\u4f5c\u7528\u57df\uff09<\/strong><\/p>\n<p>\u5757\u4f5c\u7528\u57df\uff0c\u6216\u5c40\u90e8\u4f5c\u7528\u57df\uff0c\u5c06\u53d8\u91cf\u7684\u53ef\u89c1\u6027\u9650\u5236\u5728\u5b9a\u4e49\u5b83\u4eec\u7684\u5757\u4e2d\u3002\u5728\u5757 ({}) \u5185\u7528 let \u6216 const \u58f0\u660e\u7684\u53d8\u91cf\u53ea\u80fd\u5728\u8be5\u5757\u5185\u8bbf\u95ee\u3002\u53e6\u4e00\u65b9\u9762\uff0cvar \u4e0d\u9075\u5faa\u5757\u4f5c\u7528\u57df\uff0c\u800c\u662f\u9075\u5faa\u51fd\u6570\u4f5c\u7528\u57df\u3002<\/p>\n<pre>if (true) {\n    let blockvar = \"i'm block-scoped!\";\n    console.log(blockvar); \/\/ output: i'm block-scoped!\n}\n\nconsole.log(blockvar); \/\/ error: blockvar is not defined\n\n<\/pre>\n<p>\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0cblockvar \u53ea\u80fd\u5728 if \u5757\u5185\u8bbf\u95ee\uff0c\u7528 let \u6f14\u793a\u5757\u4f5c\u7528\u57df\u3002\u5728\u5904\u7406\u5faa\u73af\u548c\u6761\u4ef6\u65f6\uff0c\u8fd9\u79cd\u884c\u4e3a\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<p><strong>4\u3002\u8303\u56f4\u94fe<\/strong><\/p>\n<p>\u4f5c\u7528\u57df\u94fe\u662f javascript \u7684\u673a\u5236\uff0c\u5b83\u901a\u8fc7\u5728\u591a\u4e2a\u4f5c\u7528\u57df\u4e2d\u5411\u4e0a\u79fb\u52a8\u6765\u67e5\u627e\u53d8\u91cf\u503c\uff0c\u76f4\u5230\u627e\u5230\u53d8\u91cf\u6216\u5230\u8fbe\u5168\u5c40\u4f5c\u7528\u57df\u3002\u6b64\u8fc7\u7a0b\u901a\u8fc7\u8bcd\u6cd5\u4f5c\u7528\u57df\u8fdb\u884c\uff0c\u8fd9\u610f\u5473\u7740\u4ee3\u7801\u7684\u7ed3\u6784\uff08\u7f16\u5199\u51fd\u6570\u7684\u4f4d\u7f6e\uff09\u51b3\u5b9a\u9996\u5148\u641c\u7d22\u54ea\u4e2a\u4f5c\u7528\u57df\u3002<\/p>\n<pre>let globalVar = \"I'm global!\";\n\nfunction outerFunction() {\n    let outerVar = \"I'm outer!\";\n\n    function innerFunction() {\n        let innerVar = \"I'm inner!\";\n\n        console.log(globalVar); \/\/ Accessible due to scope chaining\n        console.log(outerVar);  \/\/ Accessible due to scope chaining\n        console.log(innerVar);  \/\/ Directly accessible\n    }\n\n    innerFunction();\n}\n\nouterFunction();\n\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff1a<\/p>\n<ol>\n<li>\u7531\u4e8e\u4f5c\u7528\u57df\u94fe\uff0cinnerfunction \u53ef\u4ee5\u8bbf\u95eeinnervar\u3001outervar \u548cglobalvar\u3002<\/li>\n<li>javascript \u9996\u5148\u68c0\u67e5\u6bcf\u4e2a\u53d8\u91cf\u7684\u5c40\u90e8\u4f5c\u7528\u57df (innerfunction)\uff0c\u7136\u540e\u68c0\u67e5\u5c01\u95ed\u51fd\u6570\u7684\u4f5c\u7528\u57df (outerfunction)\uff0c\u6700\u540e\u68c0\u67e5\u5168\u5c40\u4f5c\u7528\u57df\u3002<\/li>\n<\/ol>\n<p>\u5982\u679c\u5728\u4efb\u4f55\u8fd9\u4e9b\u4f5c\u7528\u57df\u4e2d\u90fd\u627e\u4e0d\u5230\u53d8\u91cf\uff0cjavascript \u4f1a\u629b\u51fa referenceerror\u3002<\/p>\n<p><strong>5\u3002\u8303\u56f4\u5982\u4f55\u5f71\u54cd\u60a8\u7684\u4ee3\u7801<\/strong><\/p>\n<p>\u7406\u89e3\u548c\u5229\u7528 javascript \u4e2d\u7684\u4f5c\u7528\u57df\u94fe\u548c\u8bcd\u6cd5\u73af\u5883\u53ef\u4ee5\u4f7f\u60a8\u7684\u4ee3\u7801\u66f4\u52a0\u9ad8\u6548\u548c\u5b89\u5168\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6700\u4f73\u5b9e\u8df5\uff1a<\/p>\n<ul>\n<li>\u6700\u5c0f\u5316\u5168\u5c40\u53d8\u91cf\uff1a\u592a\u591a\u7684\u5168\u5c40\u53d8\u91cf\u53ef\u80fd\u4f1a\u5bfc\u81f4\u610f\u5916\u9519\u8bef\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u591a\u4e2a\u811a\u672c\u65f6\u3002<\/li>\n<li>\u5bf9\u53d8\u91cf\u4f7f\u7528\u5757\u4f5c\u7528\u57df\uff1a\u4f18\u5148\u4f7f\u7528 let \u548c const \u800c\u4e0d\u662f var \u6765\u5229\u7528\u5757\u4f5c\u7528\u57df\u5e76\u907f\u514d\u610f\u5916\u7684\u53d8\u91cf\u6cc4\u6f0f\u3002<\/li>\n<li>\u5728\u95ed\u5305\u4e2d\u5229\u7528\u8bcd\u6cd5\u4f5c\u7528\u57df\uff1a\u4fdd\u7559\u5bf9\u5176\u76f4\u63a5\u4f5c\u7528\u57df\u4e4b\u5916\u7684\u53d8\u91cf\u7684\u8bbf\u95ee\u6743\u9650\u7684\u51fd\u6570\u79f0\u4e3a\u95ed\u5305\u3002\u95ed\u5305\u5bf9\u4e8e\u521b\u5efa\u6a21\u5757\u5316\u548c\u79c1\u6709\u4ee3\u7801\u975e\u5e38\u5f3a\u5927\u3002<\/li>\n<\/ul>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>javascript \u4e2d\u7684\u4f5c\u7528\u57df\u548c\u4f5c\u7528\u57df\u94fe\u5bf9\u4e8e\u63a7\u5236\u4ee3\u7801\u4e2d\u7684\u53d8\u91cf\u53ef\u8bbf\u95ee\u6027\u548c\u5185\u5b58\u4f7f\u7528\u81f3\u5173\u91cd\u8981\u3002\u901a\u8fc7\u4e86\u89e3\u5168\u5c40\u4f5c\u7528\u57df\u3001\u51fd\u6570\u4f5c\u7528\u57df\u548c\u5757\u4f5c\u7528\u57df\u7684\u7ec6\u5fae\u5dee\u522b\u4ee5\u53ca\u8bcd\u6cd5\u73af\u5883\u7684\u6982\u5ff5\uff0c\u60a8\u53ef\u4ee5\u7f16\u5199\u66f4\u6709\u6548\u4e14\u65e0\u9519\u8bef\u7684\u4ee3\u7801\u3002\u4f7f\u7528\u8fd9\u4e9b\u539f\u5219\u660e\u667a\u5730\u7ba1\u7406\u53d8\u91cf\u5e76\u521b\u5efa\u66f4\u5e72\u51c0\u3001\u66f4\u6a21\u5757\u5316\u7684 javascript \u5e94\u7528\u7a0b\u5e8f\uff01<\/p>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664    <\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   wps\u6f14\u793a\u6587\u6863\u5982\u4f55\u8f7b\u677e\u8f6c\u4e3a\u89c6\u9891\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3 JavaScript \u4e2d\u7684\u4f5c\u7528\u57df\u548c\u4f5c\u7528\u57df\u94fe \u6536\u85cf \u76ee\u524d\u7c73\u4e91\u4e0a\u5df2\u7ecf\u6709\u5f88\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u6587\u7ae0\u4e86\uff0c\u81ea\u5df1\u5728\u521d\u6b21\u9605\u8bfb\u8fd9\u4e9b\u6587\u7ae0\u4e2d\uff0c\u4e5f\u89c1\u8bc6\u5230\u4e86\u5f88\u591a\u5b66\u4e60\u601d\u8def\uff1b\u90a3\u4e48\u672c\u6587\u300a\u4e86\u89e3 JavaScript \u4e2d\u7684\u4f5c\u7528\u57df\u548c\u4f5c\u7528\u57df\u94fe\u300b\uff0c\u4e5f\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff0c\u5982\u679c\u9605\u8bfb\u5b8c\u540e\u771f\u7684\u5bf9\u4f60\u5b66\u4e60\u6587\u7ae0\u6709\u5e2e\u52a9\uff0c\u6b22\u8fce\u52a8\u52a8\u624b\u6307\uff0c\u8bc4\u8bba\u7559\u8a00\u5e76\u5206\u4eab~ javascript \u5f00\u53d1\u4eba\u5458\u7ecf\u5e38\u4f1a\u9047\u5230\u4f5c\u7528\u57df\u3001\u4f5c\u7528\u57df\u94fe\u3001\u8bcd\u6cd5\u73af\u5883\u548c\u4e0d\u540c\u7c7b\u578b\u7684\u4f5c\u7528\u57df\uff08\u5168\u5c40\u4f5c\u7528\u57df\u3001\u51fd\u6570\u4f5c\u7528\u57df\u548c\u5c40\u90e8\u4f5c\u7528\u57df\uff09\u7b49\u672f\u8bed\u3002\u8fd9\u4e9b\u6982\u5ff5\u5bf9\u4e8e\u7406\u89e3\u53d8\u91cf\u548c\u51fd\u6570\u7684\u884c\u4e3a\u65b9\u5f0f\u3001\u5b83\u4eec\u7684\u53ef\u8bbf\u95ee\u6027\u4ee5\u53ca javascript \u5728\u6267\u884c\u4ee3\u7801\u65f6\u5982\u4f55\u627e\u5230\u5b83\u4eec\u81f3\u5173\u91cd\u8981\u3002\u5728\u672c\u535a\u5ba2\u4e2d\uff0c\u6211\u4eec\u5c06\u5206\u89e3\u8fd9\u4e9b\u4e3b\u9898\uff0c\u4ee5\u5e2e\u52a9\u60a8\u638c\u63e1 javascript \u4e2d\u7684\u4f5c\u7528\u57df\u548c\u4f5c\u7528\u57df\u94fe\u3002 1\u3002\u4ec0\u4e48\u662f\u8303\u56f4\uff1f \u5728 javascript \u4e2d\uff0c\u4f5c\u7528\u57df\u5b9a\u4e49\u4e86\u53d8\u91cf\u548c\u51fd\u6570\u7684\u53ef\u8bbf\u95ee\u6027\u6216\u53ef\u89c1\u6027\u3002\u5b83\u51b3\u5b9a\u53d8\u91cf\u5728\u54ea\u91cc\u53ef\u7528\u4ee5\u53ca\u5728\u54ea\u91cc\u4e0d\u53ef\u7528\u3002\u4f8b\u5982\uff0c\u5728\u4e00\u4e2a\u51fd\u6570\u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf\u53ef\u80fd\u65e0\u6cd5\u5728\u53e6\u4e00\u51fd\u6570\u4e2d\u6216\u5168\u5c40\u8bbf\u95ee\u3002 javascript \u6709\u51e0\u79cd\u7c7b\u578b\u7684\u4f5c\u7528\u57df\uff0c\u60a8\u5e94\u8be5\u6ce8\u610f\uff1a \u5168\u7403\u8303\u56f4 \u529f\u80fd\u8303\u56f4 \u5757\/\u672c\u5730\u8303\u56f4 \u4e86\u89e3\u8fd9\u4e9b\u4e0d\u540c\u7c7b\u578b\u7684\u4f5c\u7528\u57df\u53ef\u4ee5\u5e2e\u52a9\u60a8\u7f16\u5199\u9ad8\u6548\u4e14\u65e0\u9519\u8bef\u7684\u4ee3\u7801\u3002 2\u3002\u8bcd\u6c47\u73af\u5883 \u5728\u6df1\u5165\u7814\u7a76\u4e0d\u540c\u7c7b\u578b\u7684\u8303\u56f4\u4e4b\u524d\uff0c\u4e86\u89e3\u8bcd\u6cd5\u73af\u5883\u975e\u5e38\u91cd\u8981\u3002\u6bcf\u6b21\u8fd0\u884c javascript \u4ee3\u7801\u65f6\uff0c\u5b83\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u8bcd\u6cd5\u73af\u5883\u6765\u7ba1\u7406\u4ee3\u7801\u7279\u5b9a\u90e8\u5206\u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf\u548c\u51fd\u6570\u3002\u8bcd\u6c47\u73af\u5883\u5305\u62ec\uff1a \u73af\u5883\u8bb0\u5f55 \u2013 \u5b58\u50a8\u8303\u56f4\u5185\u7684\u53d8\u91cf\u548c\u51fd\u6570\u3002 \u5bf9\u5916\u90e8\u73af\u5883\u7684\u5f15\u7528 \u2013 \u4fdd\u6301\u4e0e\u5916\u90e8\u8bcd\u6cd5\u73af\u5883\uff08\u901a\u5e38\u79f0\u4e3a\u7236\u73af\u5883\uff09\u7684\u94fe\u63a5\uff0c\u8fd9\u5141\u8bb8\u8303\u56f4\u94fe\u3002 javascript \u4f7f\u7528\u8bcd\u6cd5\u73af\u5883\u6839\u636e\u4ee3\u7801\u7f16\u5199\u4f4d\u7f6e\uff08\u4e0d\u4e00\u5b9a\u662f\u6267\u884c\u4f4d\u7f6e\uff09\u6765\u786e\u5b9a\u53d8\u91cf\u7684\u53ef\u8bbf\u95ee\u6027\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u79f0\u4e3a\u8bcd\u6cd5\u4f5c\u7528\u57df\u3002 3\u3002 javascript \u4e2d\u7684\u4f5c\u7528\u57df\u7c7b\u578b a) \u5168\u7403\u8303\u56f4 \u5168\u5c40\u8303\u56f4\u610f\u5473\u7740\u53d8\u91cf\u6216\u51fd\u6570\u662f\u5728\u6700\u5916\u5c42\u4e0a\u4e0b\u6587\u4e2d\u5b9a\u4e49\u7684\uff08\u5373\u4e0d\u5728\u51fd\u6570\u6216\u5757\u5185\uff09\u3002\u5728\u5168\u5c40\u8303\u56f4\u5185\u5b9a\u4e49\u7684\u53d8\u91cf\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u7684\u4efb\u4f55\u4f4d\u7f6e\u8bbf\u95ee\u3002 let globalvar = &#8220;i&#8217;m global!&#8221;; function printglobalvar() { console.log(globalvar); \/\/ accessible here } printglobalvar(); [&hellip;]<\/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-52626","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52626","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=52626"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52626\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52626"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52626"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}