{"id":1411,"date":"2022-07-16T15:08:04","date_gmt":"2022-07-16T07:08:04","guid":{"rendered":"https:\/\/zhuxinyong.com\/?p=1411"},"modified":"2022-07-16T15:25:30","modified_gmt":"2022-07-16T07:25:30","slug":"33-jian-tou-han-shu-he-new-arguments-yi-ji-super-2","status":"publish","type":"post","link":"https:\/\/zhuxinyong.com\/?p=1411","title":{"rendered":"33 &#8211; \u7bad\u5934\u51fd\u6570\u548c new \u3001arguments \u4ee5\u53ca super \u5173\u952e\u5b57"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/07\/16579553284012.jpg\" alt=\"\" \/><\/p>\n<p>\u539f\u6587\u5730\u5740\uff1a<a href=\"https:\/\/dev.to\/bhagatparwinder\/arrow-function-and-the-new-arguments-super-keyword-2d1l\" target=\"_blank\" rel=\"noopener\">https:\/\/dev.to\/bhagatparwinder\/arrow-function-and-the-new-arguments-super-keyword-2d1l<\/a><\/p>\n<p>\u6211\u4eec\u4e4b\u524d\u5df2\u7ecf\u5b66\u8fc7\u4e86\u7bad\u5934\u51fd\u6570\u4ee5\u53ca\u5b83\u7684 this \u5173\u952e\u5b57\u7684\u4e0d\u540c\u3002<\/p>\n<p>\u5f53\u6d89\u53ca\u5230 <code>this<\/code> \u5173\u952e\u5b57\u7684\u65f6\u5019\u7bad\u5934\u51fd\u6570\u4f1a\u8868\u73b0\u7684\u4e0d\u540c\uff0c\u540c\u65f6\u5b83\u4e5f\u6ca1\u6709\u7ed1\u5b9a\u7684 <code>arguments<\/code>\u3001<code>new<\/code> \u548c <code>super<\/code> \u5173\u952e\u5b57\u3002<\/p>\n<h2><a id=\"arguments\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>Arguments<\/h2>\n<p><code>arguments<\/code> \u5bf9\u8c61\u662f\u4e00\u4e2a\u7c7b\u6570\u7ec4\u4f7f\u6211\u4eec\u53ef\u4ee5\u83b7\u53d6\u6240\u6709\u4f20\u9012\u7ed9\u51fd\u6570\u7684\u53c2\u6570\u3002<\/p>\n<pre><code class=\"language-plain_text\">function addThreeNumbers(a, b, c) {\n    console.log(arguments.length); \/\/ 3\n    console.log(arguments[0]); \/\/ 4\n    console.log(arguments[1]); \/\/ 17\n    console.log(arguments[2]); \/\/ 22\n    return a + b + c;\n}\n\nconsole.log(addThreeNumbers(4, 17, 22)); \/\/ 43\n<\/code><\/pre>\n<p>\u7bad\u5934\u51fd\u6570\u7684\u53c2\u6570\u662f\u5bf9\u4f5c\u7528\u57df\u53c2\u6570\u7684\u5f15\u7528\u3002<\/p>\n<pre><code class=\"language-plain_text\">const bar = x =&gt; console.log(arguments);\n\nconsole.log(bar()); \/\/ Uncaught ReferenceError: arguments is not defined\n<\/code><\/pre>\n<p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u66ff\u4ee3\u65b9\u6cd5\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u5f53\u4f60\u9700\u8981\u83b7\u53d6\u53c2\u6570\u65f6\uff0c\u4f7f\u7528 <code>rest<\/code> \u64cd\u4f5c\u7b26\u3002<\/p>\n<pre><code class=\"language-plain_text\">const addThreeNumbers = (...args) =&gt; {\n    console.log(args.length); \/\/ 3\n    console.log(args[0]); \/\/ 4\n    console.log(args[1]); \/\/ 17\n    console.log(args[2]); \/\/ 22\n    return args[0] + args[1] + args[2];\n}\n\nconsole.log(addThreeNumbers(4, 17, 22)); \/\/ 43\n<\/code><\/pre>\n<p>\u4f60\u53ef\u4ee5\u901a\u8fc7\u89e3\u6784\u4f7f\u4ee3\u7801\u66f4\u7b80\u6d01\u3002<\/p>\n<pre><code class=\"language-plain_text\">const addThreeNumbers = (...args) =&gt; {\n\n    const [a, b, c] = args;\n\n    console.log(args.length); \/\/ 3\n    console.log(a); \/\/ 4\n    console.log(b); \/\/ 17\n    console.log(c); \/\/ 22\n\n    return a + b + c;\n}\n\nconsole.log(addThreeNumbers(4, 17, 22)); \/\/ 43\n<\/code><\/pre>\n<h2><a id=\"new\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>New<\/h2>\n<p>\u7bad\u5934\u51fd\u6570\u4e0d\u80fd\u7528\u4f5c\u6784\u9020\u5668\uff0c\u5f53\u548c new \u4e00\u8d77\u4f7f\u7528\u65f6\u4f1a\u62a5\u9519\u3002<\/p>\n<pre><code class=\"language-plain_text\">const foo = () =&gt; { };\nconst bar = new foo(); \/\/ foo is not a constructor\n<\/code><\/pre>\n<p>\u7bad\u5934\u51fd\u6570\u6ca1\u6709 <code>Construct<\/code> \u5185\u90e8\u65b9\u6cd5\u3002<\/p>\n<h2><a id=\"super\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>Super<\/h2>\n<p>\u6309\u7167 ES \u89c4\u8303\u7bad\u5934\u51fd\u6570\u4e0d\u80fd\u4e0e <code>super<\/code> \u5173\u952e\u5b57\u4e00\u8d77\u4f7f\u7528\u3002<\/p>\n<pre><code class=\"language-plain_text\">class Base {\n    public foo = () =&gt; {\n        console.log(&quot;Hello&quot;);\n    }\n}\n\nclass Child extends Base {\n    public bar() {\n        super.foo(); \/\/ Only public and protected methods of the base class are accessible via the 'super' keyword.\n    };\n}\n<\/code><\/pre>\n<p>\u7136\u800c\uff0c\u5728\u8fd9\u79cd\u573a\u666f\u4e0b\u4f7f\u7528\u5e38\u89c4\u7684\u51fd\u6570\u3002<\/p>\n<pre><code class=\"language-plain_text\">class Base {\n    public foo() {\n        console.log(&quot;Hello&quot;);\n    }\n}\n\nclass Child extends Base {\n    public bar() {\n        super.foo();\n    };\n}\n<\/code><\/pre>\n<h2><a id=\"%E5%BD%A9%E8%9B%8B\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u5f69\u86cb<\/h2>\n<ul>\n<li>\u7bad\u5934\u51fd\u6570\u6ca1\u6709 <code>prototype<\/code> \u5c5e\u6027<\/li>\n<\/ul>\n<pre><code class=\"language-plain_text\">var Foo = () =&gt; { };\n   console.log(Foo.prototype); \/\/ undefined\n<\/code><\/pre>\n<ul>\n<li>\u7bad\u5934\u51fd\u6570\u4e0d\u80fd\u7528\u4f5c generators \uff0c\u56e0\u4e3a\u5b83\u4eec\u6ca1\u6709 <code>yield<\/code> \u5173\u952e\u5b57\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u5730\u5740\uff1ahttps:\/\/dev.to\/bhagatparwinder\/arrow-function&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,20,3],"tags":[137,83,197],"class_list":["post-1411","post","type-post","status-publish","format-standard","hentry","category-all","category-frontend","category-tech","tag-arrow-function","tag-new","tag-this"],"_links":{"self":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1411","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1411"}],"version-history":[{"count":1,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1411\/revisions"}],"predecessor-version":[{"id":1412,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1411\/revisions\/1412"}],"wp:attachment":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}