{"id":3171,"date":"2024-11-10T12:42:58","date_gmt":"2024-11-10T04:42:58","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3171\/"},"modified":"2024-11-10T12:42:58","modified_gmt":"2024-11-10T04:42:58","slug":"js%e5%87%bd%e6%95%b0%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3171\/","title":{"rendered":"js\u51fd\u6570\u5982\u4f55\u4f7f\u7528"},"content":{"rendered":"<blockquote><p>\n  javascript \u51fd\u6570\u662f\u4e00\u7ec4\u53ef\u91cd\u7528\u7684\u4ee3\u7801\u5757\uff0c\u7528\u4e8e\u6267\u884c\u6307\u5b9a\u4efb\u52a1\uff0c\u4f7f\u7528\u65b9\u6cd5\u662f\u901a\u8fc7\u51fd\u6570\u540d\u79f0\u8c03\u7528\u5e76\u4f20\u9012\u53c2\u6570\u3002\u5b83\u4eec\u901a\u8fc7\u6784\u9020\u51fd\u6570\u5173\u952e\u5b57\u6216 es6 \u4e2d\u7684\u7bad\u5934\u51fd\u6570\u521b\u5efa\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a\u6784\u9020\u51fd\u6570\u5173\u952e\u5b57\uff1afunction functionname(parameters) { \/\/ \u51fd\u6570\u4f53}\u7bad\u5934\u51fd\u6570\uff1aconst functionname = (parameters) =&gt; { \/\/ \u51fd\u6570\u4f53}\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110806091694220.jpg\" class=\"aligncenter\" title=\"js\u51fd\u6570\u5982\u4f55\u4f7f\u7528\u63d2\u56fe\" alt=\"js\u51fd\u6570\u5982\u4f55\u4f7f\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>JS \u51fd\u6570\u7684\u4f7f\u7528<\/strong><\/p>\n<p><strong>\u4e00\u3001\u5b9a\u4e49<\/strong><\/p>\n<p>JavaScript \u51fd\u6570\u662f\u4e00\u7ec4\u53ef\u91cd\u7528\u7684\u4ee3\u7801\u5757\uff0c\u7528\u4e8e\u6267\u884c\u7279\u5b9a\u7684\u4efb\u52a1\u3002\u5b83\u4eec\u901a\u8fc7\u6784\u9020\u51fd\u6570\u5173\u952e\u5b57\u6216 ES6 \u4e2d\u7684\u7bad\u5934\u51fd\u6570\u521b\u5efa\u3002<\/p>\n<p><strong>\u4e8c\u3001\u8bed\u6cd5<\/strong><\/p>\n<pre>\/\/ \u6784\u9020\u51fd\u6570\u5173\u952e\u5b57\nfunction functionName(parameters) {\n  \/\/ \u51fd\u6570\u4f53\n}\n\n\/\/ \u7bad\u5934\u51fd\u6570\nconst functionName = (parameters) =&gt; {\n  \/\/ \u51fd\u6570\u4f53\n};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4e09\u3001\u4f7f\u7528<\/strong><\/p>\n<p>\u4f7f\u7528 JavaScript \u51fd\u6570\uff0c\u53ef\u4ee5\u901a\u8fc7\u5176\u540d\u79f0\u8c03\u7528\u5b83\u4eec\uff0c\u5e76\u4f20\u9012\u6240\u9700\u7684\u4efb\u4f55\u53c2\u6570\u3002<\/p>\n<pre>\/\/ \u8c03\u7528\u6784\u9020\u51fd\u6570\u5173\u952e\u5b57\u521b\u5efa\u7684\u51fd\u6570\nfunctionName(arg1, arg2);\n\n\/\/ \u8c03\u7528\u7bad\u5934\u51fd\u6570\nfunctionName(arg1, arg2);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u56db\u3001\u53c2\u6570<\/strong><\/p>\n<p>\u51fd\u6570\u53ef\u4ee5\u63a5\u53d7\u4efb\u610f\u6570\u91cf\u7684\u53c2\u6570\uff0c\u7531\u9017\u53f7\u5206\u9694\u3002\u53c2\u6570\u5728\u51fd\u6570\u4f53\u4e2d\u901a\u8fc7\u53c2\u6570\u540d\u79f0\u8bbf\u95ee\u3002<\/p>\n<p><strong>\u4e94\u3001\u8fd4\u56de\u503c<\/strong><\/p>\n<p>\u51fd\u6570\u53ef\u4ee5\u4f7f\u7528 return \u8bed\u53e5\u8fd4\u56de\u4e00\u4e2a\u503c\u3002\u5982\u679c\u672a\u6307\u5b9a\u8fd4\u56de\u8bed\u53e5\uff0c\u51fd\u6570\u5c06\u9690\u5f0f\u8fd4\u56de undefined\u3002<\/p>\n<p><strong>\u516d\u3001<\/strong><\/p>\n<p>\u51fd\u6570\u5185\u7684\u53d8\u91cf\u53ea\u80fd\u5728\u51fd\u6570\u5185\u90e8\u8bbf\u95ee\uff08\u5c40\u90e8\u4f5c\u7528\u57df\uff09\u3002\u8981\u5728\u51fd\u6570\u5916\u90e8\u8bbf\u95ee\u53d8\u91cf\uff0c\u9700\u8981\u5c06\u5176\u58f0\u660e\u4e3a\u5168\u5c40\u53d8\u91cf\u6216\u4f7f\u7528\u95ed\u5305\u3002<\/p>\n<p><strong>\u4e03\u3001\u95ed\u5305<\/strong><\/p>\n<p>\u95ed\u5305\u662f\u51fd\u6570\u5185\u90e8\u8bbf\u95ee\u5916\u90e8\u4f5c\u7528\u57df\u4e2d\u53d8\u91cf\u7684\u80fd\u529b\u3002\u8fd9\u901a\u8fc7\u4e3a\u5185\u90e8\u51fd\u6570\u521b\u5efa\u5bf9\u5916\u90e8\u4f5c\u7528\u57df\u53d8\u91cf\u7684\u5f15\u7528\u6765\u5b9e\u73b0\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>const outerVariable = 10;\n\nfunction outerFunction() {\n  const innerVariable = 20;\n\n  function innerFunction() {\n    console.log(outerVariable, innerVariable); \/\/ \u8bbf\u95ee\u5916\u90e8\u548c\u5185\u90e8\u53d8\u91cf\n  }\n\n  innerFunction();\n}\n\nouterFunction(); \/\/ \u8f93\u51fa\uff1a10 20<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjs\u51fd\u6570\u5982\u4f55\u4f7f\u7528\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>javascript \u51fd\u6570\u662f\u4e00\u7ec4\u53ef\u91cd\u7528\u7684\u4ee3\u7801\u5757\uff0c\u7528\u4e8e\u6267\u884c\u6307\u5b9a\u4efb\u52a1\uff0c\u4f7f\u7528\u65b9\u6cd5\u662f\u901a\u8fc7\u51fd\u6570\u540d\u79f0\u8c03\u7528\u5e76\u4f20\u9012\u53c2\u6570\u3002\u5b83\u4eec\u901a\u8fc7\u6784\u9020\u51fd\u6570\u5173\u952e\u5b57\u6216 es6 \u4e2d\u7684\u7bad\u5934\u51fd\u6570\u521b\u5efa\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a\u6784\u9020\u51fd\u6570\u5173\u952e\u5b57\uff1afunction functionname(parameters) { \/\/ \u51fd\u6570\u4f53}\u7bad\u5934\u51fd\u6570\uff1aconst functionname = (parameters) =&gt; { \/\/ \u51fd\u6570\u4f53} JS \u51fd\u6570\u7684\u4f7f\u7528 \u4e00\u3001\u5b9a\u4e49 JavaScript \u51fd\u6570\u662f\u4e00\u7ec4\u53ef\u91cd\u7528\u7684\u4ee3\u7801\u5757\uff0c\u7528\u4e8e\u6267\u884c\u7279\u5b9a\u7684\u4efb\u52a1\u3002\u5b83\u4eec\u901a\u8fc7\u6784\u9020\u51fd\u6570\u5173\u952e\u5b57\u6216 ES6 \u4e2d\u7684\u7bad\u5934\u51fd\u6570\u521b\u5efa\u3002 \u4e8c\u3001\u8bed\u6cd5 \/\/ \u6784\u9020\u51fd\u6570\u5173\u952e\u5b57 function functionName(parameters) { \/\/ \u51fd\u6570\u4f53 } \/\/ \u7bad\u5934\u51fd\u6570 const functionName = (parameters) =&gt; { \/\/ \u51fd\u6570\u4f53 }; \u767b\u5f55\u540e\u590d\u5236 \u4e09\u3001\u4f7f\u7528 \u4f7f\u7528 JavaScript \u51fd\u6570\uff0c\u53ef\u4ee5\u901a\u8fc7\u5176\u540d\u79f0\u8c03\u7528\u5b83\u4eec\uff0c\u5e76\u4f20\u9012\u6240\u9700\u7684\u4efb\u4f55\u53c2\u6570\u3002 \/\/ \u8c03\u7528\u6784\u9020\u51fd\u6570\u5173\u952e\u5b57\u521b\u5efa\u7684\u51fd\u6570 functionName(arg1, arg2); \/\/ \u8c03\u7528\u7bad\u5934\u51fd\u6570 functionName(arg1, arg2); [&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-3171","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3171","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=3171"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3171\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}