{"id":53161,"date":"2024-12-03T09:00:09","date_gmt":"2024-12-03T01:00:09","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53161\/"},"modified":"2024-12-03T09:00:09","modified_gmt":"2024-12-03T01:00:09","slug":"%e6%8e%8c%e6%8f%a1-javascript-%e4%b8%ad%e7%9a%84%e7%ae%ad%e5%a4%b4%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53161\/","title":{"rendered":"\u638c\u63e1 JavaScript \u4e2d\u7684\u7bad\u5934\u51fd\u6570"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u638c\u63e1 JavaScript \u4e2d\u7684\u7bad\u5934\u51fd\u6570<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span>    <\/p>\n<p>\u672c\u7bc7\u6587\u7ae0\u5411\u5927\u5bb6\u4ecb\u7ecd\u300a\u638c\u63e1 JavaScript \u4e2d\u7684\u7bad\u5934\u51fd\u6570\u300b\uff0c\u4e3b\u8981\u5305\u62ec\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241127\/17327003826746e8de59d83.jpg\" class=\"aligncenter\" title=\"\u638c\u63e1 JavaScript \u4e2d\u7684\u7bad\u5934\u51fd\u6570\u63d2\u56fe\" alt=\"\u638c\u63e1 JavaScript \u4e2d\u7684\u7bad\u5934\u51fd\u6570\u63d2\u56fe\" \/><\/p>\n<p>es6 \u4e2d\u5f15\u5165\u7684\u7bad\u5934\u51fd\u6570\u4e3a\u7f16\u5199\u51fd\u6570\u63d0\u4f9b\u4e86\u66f4\u7b80\u6d01\u7684\u8bed\u6cd5\u3002\u5b83\u4eec\u5bf9\u4e8e\u7f16\u5199\u5185\u8054\u51fd\u6570\u7279\u522b\u6709\u7528\uff0c\u5e76\u4e14\u4e0e\u4f20\u7edf\u51fd\u6570\u8868\u8fbe\u5f0f\u76f8\u6bd4\u5177\u6709\u4e00\u4e9b\u72ec\u7279\u7684\u884c\u4e3a\u3002\u5728\u672c\u535a\u5ba2\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u7bad\u5934\u51fd\u6570\u7684\u57fa\u7840\u77e5\u8bc6\u3001\u5b83\u4eec\u7684\u4ee3\u7801\u7ed3\u6784\u3001\u7279\u6b8a\u529f\u80fd\u4ee5\u53ca\u5b83\u4eec\u5982\u4f55\u4e0e\u5404\u79cd javascript \u7ed3\u6784\u4ea4\u4e92\u3002<\/p>\n<h3> <strong>\u7bad\u5934\u51fd\u6570\u7684\u57fa\u7840\u77e5\u8bc6<\/strong> <\/h3>\n<p>\u7bad\u5934\u51fd\u6570\u4f7f\u7528 <strong>=&gt;<\/strong> \u8bed\u6cd5\u5b9a\u4e49\u3002\u5b83\u4eec\u53ef\u7528\u4e8e\u521b\u5efa\u7b80\u5355\u548c\u590d\u6742\u7684\u51fd\u6570\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>let functionname = (parameters) =&gt; {\n  \/\/ code to execute\n};\n\n<\/pre>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>let greet = (name) =&gt; {\n  console.log(\"hello, \" + name + \"!\");\n};\n\ngreet(\"alice\"); \/\/ output: hello, alice!\n\n<\/pre>\n<h3> <strong>\u4ee3\u7801\u7ed3\u6784<\/strong> <\/h3>\n<p>\u7bad\u5934\u51fd\u6570\u5177\u6709\u7b80\u6d01\u7684\u8bed\u6cd5\uff0c\u53ef\u4ee5\u8fdb\u4e00\u6b65\u7b80\u5316\u5355\u884c\u51fd\u6570\u3002<\/p>\n<p><strong>\u5355\u4e2a\u53c2\u6570\uff1a<\/strong><\/p>\n<pre>let square = x =&gt; x * x;\nconsole.log(square(5)); \/\/ output: 25\n\n<\/pre>\n<p><strong>\u591a\u4e2a\u53c2\u6570\uff1a<\/strong><\/p>\n<pre>let add = (a, b) =&gt; a + b;\nconsole.log(add(3, 4)); \/\/ output: 7\n\n<\/pre>\n<p><strong>\u65e0\u53c2\u6570\uff1a<\/strong><\/p>\n<pre>let sayhello = () =&gt; console.log(\"hello!\");\nsayhello(); \/\/ output: hello!\n\n<\/pre>\n<p><strong>\u9690\u5f0f\u8fd4\u56de\uff1a<\/strong><br \/> \u5bf9\u4e8e\u5355\u884c\u51fd\u6570\uff0c<strong>return<\/strong> \u8bed\u53e5\u53ef\u4ee5\u7701\u7565\u3002<\/p>\n<pre>let multiply = (a, b) =&gt; a * b;\nconsole.log(multiply(2, 3)); \/\/ output: 6\n\n<\/pre>\n<h3> <strong>javascript \u7279\u4ef7<\/strong> <\/h3>\n<p>\u7bad\u5934\u51fd\u6570\u6709\u4e00\u4e9b\u7279\u6b8a\u7684\u884c\u4e3a\u4ee5\u53ca\u4e0e\u5176\u4ed6 javascript \u7ed3\u6784\u7684\u4ea4\u4e92\u3002<\/p>\n<h3> <strong>\u4e25\u683c\u6a21\u5f0f<\/strong> <\/h3>\n<p>\u7bad\u5934\u51fd\u6570\u6ca1\u6709\u81ea\u5df1\u7684 <strong>this<\/strong> \u4e0a\u4e0b\u6587\u3002\u76f8\u53cd\uff0c\u5b83\u4eec\u4ece\u5468\u56f4\u7684\u8bcd\u6c47\u4e0a\u4e0b\u6587\u7ee7\u627f <strong>this<\/strong>\u3002\u8fd9\u4f7f\u5f97\u5b83\u4eec\u5728\u975e\u65b9\u6cd5\u51fd\u6570\u548c\u56de\u8c03\u4e2d\u7279\u522b\u6709\u7528\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>function person() {\n  this.age = 0;\n\n  setinterval(() =&gt; {\n    this.age++;\n    console.log(this.age);\n  }, 1000);\n}\n\nlet p = new person();\n\/\/ output: 1 2 3 4 ...\n\n<\/pre>\n<p><strong>\u8bf4\u660e\uff1a<\/strong><\/p>\n<ul>\n<li><strong>setinterval<\/strong>\u5185\u90e8\u7684\u7bad\u5934\u51fd\u6570\u4ece<strong>person<\/strong>\u51fd\u6570\u7ee7\u627f<strong>this<\/strong>\uff0c\u5141\u8bb8\u5b83\u8bbf\u95ee\u548c\u4fee\u6539<strong>this.age<\/strong>\u3002<\/li>\n<\/ul>\n<h3> <strong>\u53d8\u91cf<\/strong> <\/h3>\n<p>\u7bad\u5934\u51fd\u6570\u53ef\u4ee5\u8bbf\u95ee\u5468\u56f4\u8303\u56f4\u5185\u7684\u53d8\u91cf\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>let count = 0;\n\nlet increment = () =&gt; {\n  count++;\n  console.log(count);\n};\n\nincrement(); \/\/ output: 1\nincrement(); \/\/ output: 2\n\n<\/pre>\n<h3> <strong>\u4e0e\u5176\u4ed6\u7ed3\u6784\u7684\u4ea4\u4e92<\/strong> <\/h3>\n<p>\u7bad\u5934\u51fd\u6570\u53ef\u4ee5\u4e0e\u5404\u79cd javascript \u7ed3\u6784\u4e00\u8d77\u4f7f\u7528\uff0c\u4f8b\u5982\u5faa\u73af\u3001<strong>switch<\/strong> \u8bed\u53e5\u548c\u5176\u4ed6\u51fd\u6570\u3002<\/p>\n<h3> <strong>\u5faa\u73af<\/strong> <\/h3>\n<pre>let numbers = [1, 2, 3, 4, 5];\n\nnumbers.foreach(number =&gt; {\n  console.log(number * 2);\n});\n\/\/ output: 2 4 6 8 10\n\n<\/pre>\n<h3> <strong>\u5f00\u5173\u6784\u9020<\/strong> <\/h3>\n<pre>let getdayname = (day) =&gt; {\n  switch (day) {\n    case 1:\n      return \"monday\";\n    case 2:\n      return \"tuesday\";\n    case 3:\n      return \"wednesday\";\n    case 4:\n      return \"thursday\";\n    case 5:\n      return \"friday\";\n    case 6:\n      return \"saturday\";\n    case 7:\n      return \"sunday\";\n    default:\n      return \"invalid day\";\n  }\n};\n\nconsole.log(getdayname(3)); \/\/ output: wednesday\n\n<\/pre>\n<h3> <strong>\u529f\u80fd<\/strong> <\/h3>\n<p>\u7bad\u5934\u51fd\u6570\u53ef\u4ee5\u7528\u4f5c\u5176\u4ed6\u51fd\u6570\u4e2d\u7684\u56de\u8c03\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>let processArray = (arr, callback) =&gt; {\n  for (let i = 0; i &lt; arr.length; i++) {\n    callback(arr[i]);\n  }\n};\n\nlet numbers = [1, 2, 3, 4, 5];\n\nprocessArray(numbers, number =&gt; {\n  console.log(number * 2);\n});\n\/\/ Output: 2 4 6 8 10\n\n<\/pre>\n<h3> <strong>\u603b\u7ed3<\/strong> <\/h3>\n<ul>\n<li> <strong>\u7bad\u5934\u51fd\u6570<\/strong>\uff1a\u63d0\u4f9b\u5b9a\u4e49\u51fd\u6570\u7684\u7b80\u6d01\u8bed\u6cd5\u3002<\/li>\n<li> <strong>\u4ee3\u7801\u7ed3\u6784<\/strong>\uff1a\u5355\u884c\u51fd\u6570\u548c\u9690\u5f0f\u8fd4\u56de\u7684\u7b80\u5316\u8bed\u6cd5\u3002<\/li>\n<li> <strong>\u4e25\u683c\u6a21\u5f0f<\/strong>\uff1a\u4ece\u5468\u56f4\u7684\u8bcd\u6c47\u4e0a\u4e0b\u6587\u7ee7\u627f<strong>this<\/strong>\u3002<\/li>\n<li> <strong>\u53d8\u91cf<\/strong>\uff1a\u53ef\u4ee5\u8bbf\u95ee\u5468\u56f4\u8303\u56f4\u7684\u53d8\u91cf\u3002<\/li>\n<li> <strong>\u4ea4\u4e92<\/strong>\uff1a\u53ef\u4e0e\u5faa\u73af\u3001<strong>switch<\/strong> \u8bed\u53e5\u548c\u5176\u4ed6\u51fd\u6570\u4e00\u8d77\u4f7f\u7528\u3002<\/li>\n<li> <strong>\u51fd\u6570<\/strong>\uff1a\u53ef\u7528\u4f5c\u5176\u4ed6\u51fd\u6570\u4e2d\u7684\u56de\u8c03\u3002<\/li>\n<\/ul>\n<h3> <strong>\u7ed3\u8bba<\/strong> <\/h3>\n<p>\u7bad\u5934\u51fd\u6570\u662f\u5728 javascript \u4e2d\u5b9a\u4e49\u51fd\u6570\u7684\u4e00\u79cd\u5f3a\u5927\u4e14\u7b80\u6d01\u7684\u65b9\u6cd5\u3002\u901a\u8fc7\u4e86\u89e3\u5b83\u4eec\u7684\u8bed\u6cd5\u3001\u7279\u6b8a\u884c\u4e3a\u4ee5\u53ca\u4e0e\u5176\u4ed6\u6784\u9020\u7684\u4ea4\u4e92\uff0c\u60a8\u5c06\u80fd\u591f\u7f16\u5199\u66f4\u9ad8\u6548\u3001\u66f4\u6613\u8bfb\u7684\u4ee3\u7801\u3002\u4e0d\u65ad\u7ec3\u4e60\u548c\u63a2\u7d22\uff0c\u52a0\u6df1\u5bf9 javascript \u4e2d\u7bad\u5934\u51fd\u6570\u7684\u7406\u89e3\u3002<\/p>\n<p>\u8bf7\u7ee7\u7eed\u5173\u6ce8\u6709\u5173 javascript \u7684\u66f4\u591a\u6df1\u5165\u535a\u5ba2\uff01\u5feb\u4e50\u7f16\u7801\uff01<\/p>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300a\u638c\u63e1 JavaScript \u4e2d\u7684\u7bad\u5934\u51fd\u6570\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/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   Mac Docker Desktop\u90e8\u7f72MySQL\u670d\u52a1\u5931\u8d25\uff1a\u5982\u4f55\u89e3\u51b3\u672c\u5730\u5ba2\u6237\u7aef\u8fde\u63a5\u62a5\u9519\u95ee\u9898\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u638c\u63e1 JavaScript \u4e2d\u7684\u7bad\u5934\u51fd\u6570 \u6536\u85cf \u672c\u7bc7\u6587\u7ae0\u5411\u5927\u5bb6\u4ecb\u7ecd\u300a\u638c\u63e1 JavaScript \u4e2d\u7684\u7bad\u5934\u51fd\u6570\u300b\uff0c\u4e3b\u8981\u5305\u62ec\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u3002 es6 \u4e2d\u5f15\u5165\u7684\u7bad\u5934\u51fd\u6570\u4e3a\u7f16\u5199\u51fd\u6570\u63d0\u4f9b\u4e86\u66f4\u7b80\u6d01\u7684\u8bed\u6cd5\u3002\u5b83\u4eec\u5bf9\u4e8e\u7f16\u5199\u5185\u8054\u51fd\u6570\u7279\u522b\u6709\u7528\uff0c\u5e76\u4e14\u4e0e\u4f20\u7edf\u51fd\u6570\u8868\u8fbe\u5f0f\u76f8\u6bd4\u5177\u6709\u4e00\u4e9b\u72ec\u7279\u7684\u884c\u4e3a\u3002\u5728\u672c\u535a\u5ba2\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u7bad\u5934\u51fd\u6570\u7684\u57fa\u7840\u77e5\u8bc6\u3001\u5b83\u4eec\u7684\u4ee3\u7801\u7ed3\u6784\u3001\u7279\u6b8a\u529f\u80fd\u4ee5\u53ca\u5b83\u4eec\u5982\u4f55\u4e0e\u5404\u79cd javascript \u7ed3\u6784\u4ea4\u4e92\u3002 \u7bad\u5934\u51fd\u6570\u7684\u57fa\u7840\u77e5\u8bc6 \u7bad\u5934\u51fd\u6570\u4f7f\u7528 =&gt; \u8bed\u6cd5\u5b9a\u4e49\u3002\u5b83\u4eec\u53ef\u7528\u4e8e\u521b\u5efa\u7b80\u5355\u548c\u590d\u6742\u7684\u51fd\u6570\u3002 \u8bed\u6cd5\uff1a let functionname = (parameters) =&gt; { \/\/ code to execute }; \u793a\u4f8b\uff1a let greet = (name) =&gt; { console.log(&#8220;hello, &#8221; + name + &#8220;!&#8221;); }; greet(&#8220;alice&#8221;); \/\/ output: hello, alice! \u4ee3\u7801\u7ed3\u6784 \u7bad\u5934\u51fd\u6570\u5177\u6709\u7b80\u6d01\u7684\u8bed\u6cd5\uff0c\u53ef\u4ee5\u8fdb\u4e00\u6b65\u7b80\u5316\u5355\u884c\u51fd\u6570\u3002 \u5355\u4e2a\u53c2\u6570\uff1a let square = x =&gt; x [&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-53161","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53161","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=53161"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53161\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}