{"id":4771,"date":"2022-03-27T20:52:35","date_gmt":"2022-03-27T12:52:35","guid":{"rendered":"https:\/\/egonlin.com\/?p=4771"},"modified":"2022-03-27T20:52:35","modified_gmt":"2022-03-27T12:52:35","slug":"%e7%ac%ac%e5%9b%9b%e8%8a%82%ef%bc%9ajs%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=4771","title":{"rendered":"\u7b2c\u56db\u8282\uff1ajs\u51fd\u6570"},"content":{"rendered":"<h1>js\u51fd\u6570<\/h1>\n<h2>1\u3001JavaScript \u51fd\u6570<\/h2>\n<h3>1-1 \u58f0\u660e\u51fd\u6570\u7684\u65b9\u5f0f<\/h3>\n<ul>\n<li>function \u5173\u952e\u5b57<\/li>\n<li>\u533f\u540d\u51fd\u6570\u65b9\u5f0f(\u8868\u8fbe\u5f0f\u65b9\u5f0f)<\/li>\n<li>Function \u6784\u9020\u51fd\u6570\u65b9\u5f0f<\/li>\n<\/ul>\n<h3>1-2 \u53c2\u6570\u95ee\u9898<\/h3>\n<ul>\n<li>\u5f62\u53c2\u548c\u5b9e\u53c2\u6570\u91cf\u95ee\u9898            <\/li>\n<li>\u53ef\u9009\u5f62\u53c2(\u53c2\u6570\u9ed8\u8ba4\u503c)            <\/li>\n<li>\u53ef\u53d8\u957f\u7684\u5b9e\u53c2\u5217\u8868:\u5b9e\u53c2\u5bf9\u8c61 aruguments <\/li>\n<\/ul>\n<h3>1-3 \u56de\u8c03\u51fd\u6570<\/h3>\n<p>\u4e00\u4e2a\u51fd\u6570\u5c31\u53ef\u4ee5\u63a5\u6536\u53e6\u4e00\u4e2a\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\uff0c\u8fd9\u79cd\u51fd\u6570\u5c31\u79f0\u4e4b\u4e3a\u56de\u8c03\u51fd\u6570(\u9ad8\u9636\u51fd\u6570)<\/p>\n<pre><code class=\"language-js\">function add(x, y, f) {\n    return f(x) + f(y);\n}\nadd(-5, 6, Math.abs)<\/code><\/pre>\n<h3>1-4 \u9012\u5f52\u51fd\u6570<\/h3>\n<p>\u51fd\u6570\u5185\u90e8\u8c03\u7528\u81ea\u5df1\u5c31\u662f\u9012\u5f52\u51fd\u6570\uff0c<\/p>\n<pre><code class=\"language-js\">\/\/\u7528\u9012\u5f52 \u5b9e\u73b0\u9636\u4e58\nfunction multiply(n) {\n    if (n == 1) {\n        return 1\n    }\n    return n * multiply(n - 1)\n}<\/code><\/pre>\n<h3>1-5 \u81ea\u8c03\u51fd\u6570<\/h3>\n<p>\u51fd\u6570\u751f\u58f0\u660e\u5b8c \u76f4\u63a5\u8c03\u7528<\/p>\n<pre><code class=\"language-js\">(function(){\n    console.log(&#039;ok&#039;)\n})()<\/code><\/pre>\n<h3>1-6 \u95ed\u5305\u51fd\u6570<\/h3>\n<p>\u5f53\u4e00\u4e2a\u51fd\u6570\u8fd4\u56de\u4e86\u4e00\u4e2a\u51fd\u6570\u540e\uff0c\u5176\u5185\u90e8\u7684\u5c40\u90e8\u53d8\u91cf\u8fd8\u88ab\u65b0\u51fd\u6570\u5f15\u7528\uff0c\u5f62\u6210\u95ed\u5305<\/p>\n<pre><code class=\"language-js\">function count() {\n    var arr = [];\n    for (var i=1; i&lt;=3; i++) {\n        arr.push((function (n) {\n            return function () {\n                return n * n;\n            }\n        })(i));\n    }\n    return arr;\n}\n\nvar results = count();\nvar f1 = results[0];\nvar f2 = results[1];\nvar f3 = results[2];\n\nf1(); \/\/ 1\nf2(); \/\/ 4\nf3(); \/\/ 9<\/code><\/pre>\n<h2>2\u3001JavaScript \u4f5c\u7528\u57df<\/h2>\n<h3>2-1 \u5c40\u90e8\u4f5c\u7528\u57df<\/h3>\n<p>\u51fd\u6570\u4e2d\u4f7f\u7528\u5b9a\u4e49\u7684\u53d8\u91cf\u5c31\u662f\u5c40\u90e8\u53d8\u91cf\uff0c\u53ea\u80fd\u5728\u672c\u51fd\u6570\u4e2d\u4f7f\u7528<\/p>\n<h3>2-2 \u5168\u5c40\u4f5c\u7528\u57df<\/h3>\n<p>\u5728\uff0c\u51fd\u6570\u5916\u9762\uff0c\u5b9a\u4e49\u7684\u53d8\u91cf\u662f\u5168\u5c40\u53d8\u91cf\u3002\u54ea\u90fd\u53ef\u4ee5\u7528<\/p>\n<p><strong>\u53d8\u91cf\u63d0\u5347<\/strong><\/p>\n<pre><code class=\"language-js\">var a = 100\nfunction demo(){\n    console.log(a)\n    var a = 200\n}<\/code><\/pre>\n<h3>2-3 \u4f5c\u7528\u57df\u94fe<\/h3>\n<p>\u51fd\u6570\u5d4c\u5957\u51fd\u6570\u4f1a\u5f62\u6210\u4f5c\u7528\u57df\u94fe<\/p>\n<pre><code class=\"language-js\">function demo(){\n    function fn(){\n        function fn1() {\n\n        }\n    }\n}<\/code><\/pre>\n<h3>2-4 \u5757\u72b6\u4f5c\u7528\u57df(ES6)<\/h3>\n<p>\u4f7f\u7528<code>let<\/code>\u5173\u952e\u5b57\u58f0\u660e\u7684\u53d8\u91cf\u4f1a\u5177\u6709\u5757\u72b6\u4f5c\u7528\u57df<\/p>\n<pre><code class=\"language-js\">for (let i = 0; i &lt; 10; i ++) {\n\n}\n\nconsole.log(i) \/\/\u53d8\u91cf\u4e0d\u5b58\u5728 Uncaught ReferenceError: i is not defined<\/code><\/pre>\n<h2><\/h2>\n","protected":false},"excerpt":{"rendered":"<p>js\u51fd\u6570 1\u3001JavaScript \u51fd\u6570 1-1 \u58f0\u660e\u51fd\u6570\u7684\u65b9\u5f0f function \u5173\u952e\u5b57 \u533f\u540d\u51fd\u6570\u65b9\u5f0f(\u8868\u8fbe [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[361,366],"tags":[],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/4771"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4771"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/4771\/revisions"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}