{"id":2535,"date":"2022-01-09T14:06:51","date_gmt":"2022-01-09T06:06:51","guid":{"rendered":"https:\/\/blog.odliken.cn\/?p=2535"},"modified":"2023-02-13T18:05:08","modified_gmt":"2023-02-13T10:05:08","slug":"es6%e5%9f%ba%e7%a1%80%e5%85%a5%e9%97%a8","status":"publish","type":"post","link":"https:\/\/blog.odjbinail.cn\/?p=2535","title":{"rendered":"ES6\u57fa\u7840\u5165\u95e8"},"content":{"rendered":"<h1>ES6 \u7b80\u4ecb<\/h1>\n<ul>\n<li>\u6b27\u6d32\u8ba1\u7b97\u673a\u5236\u9020\u5546\u534f\u4f1a<\/li>\n<li>\u6807\u51c6\u5316\u7ec4\u7ec7 ECMAScript=\u7531 ECMA \u8fd9\u4e2a\u6807\u51c6\u5316\u7ec4\u7ec7\u5236\u5b9a\u7684\u4e00\u4e2a\u8bed\u8a00\u6807\u51c6 ECMAScript=\u8bed\u6cd5+API<\/li>\n<\/ul>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022080614470756.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022080614470756.png\" alt=\"\" \/><\/p><\/noscript>\n<h3>ES \u4e0e JavaScript \u7684\u5173\u7cfb<\/h3>\n<ul>\n<li>JavaScript(\u6d4f\u89c8\u5668\u7aef)=ECMAScript(\u8bed\u6cd5+API)+DOM+BOM<\/li>\n<\/ul>\n<h2>let \u548c const<\/h2>\n<ul>\n<li>var ,let \u4ee3\u66ff var\uff0c\u58f0\u660e\u53d8\u91cf,\u53d8\u91cf\u4e00\u65e6\u521d\u59cb\u5316\u4e4b\u540e,\u8fd8\u53ef\u4ee5\u91cd\u65b0\u8d4b\u503c<\/li>\n<li>const \u58f0\u660e\u5e38\u91cf constant,\u5e38\u91cf\u4e00\u65e6\u521d\u59cb\u5316,\u5c31\u4e0d\u80fd\u91cd\u65b0\u8d4b\u503c\u4e86,\u5426\u5219\u5c31\u4f1a\u62a5\u9519<\/li>\n<li>const \u5c31\u662f\u4e3a\u4e86\u90a3\u4e9b\u4e00\u65e6\u521d\u59cb\u5316\u5c31\u4e0d\u5e0c\u671b\u91cd\u65b0\u8d4b\u503c\u7684\u60c5\u51b5\u8bbe\u8ba1\u7684<\/li>\n<li>\u4e0d\u77e5\u9053\u7528\u4ec0\u4e48\u7684\u65f6\u5019\uff0c\u5c31\u7528 const<\/li>\n<li>\u6ce8\u610f:\n<ul>\n<li>\u4f7f\u7528 const \u58f0\u660e\u5e38\u91cf,\u4e00\u65e6\u58f0\u660e,\u5c31\u5fc5\u987b\u7acb\u5373\u521d\u59cb\u5316,\u4e0d\u80fd\u7559\u5230\u4ee5\u540e\u8d4b\u503c<\/li>\n<li>const \u58f0\u660e\u7684\u5e38\u91cf,\u5141\u8bb8\u5728\u4e0d\u91cd\u65b0\u8d4b\u503c\u7684\u60c5\u51b5\u4e0b\u4fee\u6539\u5b83\u7684\u503c<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>let const \u4e0e var \u7684\u533a\u522b<\/h2>\n<h4>1.\u91cd\u590d\u58f0\u660e<\/h4>\n<ul>\n<li>\u5df2\u7ecf\u5b58\u5728\u7684\u53d8\u91cf\u6216\u5e38\u91cf\uff0c\u53c8\u58f0\u660e\u7684\u4e00\u904d\n<ul>\n<li>var \u5141\u8bb8\u91cd\u590d\u58f0\u660e\uff0clet\uff0cconst \u4e0d\u5141\u8bb8<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>2.\u53d8\u91cf\u63d0\u5347<\/h4>\n<ul>\n<li>var \u4f1a\u63d0\u5347\u53d8\u91cf\u7684\u58f0\u660e\u5230\u5f53\u524d\u4f5c\u7528\u57df\u7684\u9876\u90e8[\u53d8\u91cf\u53ef\u4ee5\u5728\u58f0\u660e\u4e4b\u524d\u4f7f\u7528]<\/li>\n<li>let,const \u4e0d\u5b58\u5728\u53d8\u91cf\u63d0\u5347<\/li>\n<li>\u517b\u6210\u826f\u597d\u7684\u7f16\u7a0b\u4e60\u60ef\uff0c\u5bf9\u4e8e\u6240\u6709\u7684\u53d8\u91cf\u6216\u5e38\u91cf\uff0c\u505a\u5230\u5148\u58f0\u660e\uff0c\u540e\u4f7f\u7528<\/li>\n<\/ul>\n<h4>3.\u6682\u65f6\u6027\u6b7b\u533a<\/h4>\n<ul>\n<li>\u53ea\u8981\u4f5c\u7528\u57df\u5185\u5b58\u5728 let\uff0cconst\uff0c\u5b83\u4eec\u6240\u58f0\u660e\u7684\u53d8\u91cf\u6216\u5e38\u91cf\u5c31\u81ea\u52a8\u201c\u7ed1\u5b9a\u201d\u8fd9\u4e2a\u533a\u57df\uff0c\u4e0d\u518d\u53d7\u5230\u5916\u90e8\u4f5c\u7528\u57df\u7684\u5f71\u54cd let const \u5b58\u5728\u6682\u65f6\u6027\u6b7b\u533a<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code>let a=2;\nlet b=1;\nfunction func(){\nconsole.log(b);\/\/1\n\/\/console.log(a);\n\/\/let a=1;\n}\nfunc();<\/code><\/pre>\n<h4>4.window \u5bf9\u8c61\u7684\u5c5e\u6027\u548c\u65b9\u6cd5(\u5168\u5c40\u4f5c\u7528\u57df\u4e2d)<\/h4>\n<ul>\n<li>\u5168\u5c40\u4f5c\u7528\u57df\u4e2d\uff0cvar \u58f0\u660e\u7684\u53d8\u91cf\uff0c\u901a\u8fc7 function \u58f0\u660e\u7684\u51fd\u6570\uff0c\u4f1a\u81ea\u52a8\u53d8\u6210 window \u5bf9\u8c61\u7684\u5c5e\u6027\u6216\u65b9\u6cd5,, let const \u4e0d\u4f1a<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code>\/\/var \/function\nvar age=18\uff1b\nfunction add(){}\nconsole.log(window.age);\/\/18\nconsole.log(window.add===add);\/\/true\n\n\/\/let\/const\nlet age=18\uff1b\nconst add=function (){}\nconsole.log(window.age);\/\/undefined\nconsole.log(window.add===add);\/\/undefined<\/code><\/pre>\n<h4><strong><em>\u5757\u7ea7\u4f5c\u7528\u57df<\/em><\/strong><\/h4>\n<ul>\n<li>var \u6ca1\u6709\u5757\u7ea7\u4f5c\u7528\u57df<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code>for(var i=0;i&lt;3;i++){\n    \/\/console.log(i);\/\/0,1,2\n}\n\/\/\u5168\u5c40\u4f5c\u7528\u57df,\u6240\u4ee5\u662f 3\nconsole.log(i);\/\/3<\/code><\/pre>\n<ul>\n<li>let \/ const \u6709\u5757\u7ea7\u4f5c\u7528\u57df<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code>for(let i=0; i&lt;3; i++){\n    \/\/console.log(i);\/\/0,1,2\n}\ni \u548c for \u5171\u540c\u6784\u6210\u4e86\u4e00\u4e2a\u5757\u7ea7\u4f5c\u7528\u57df\nconsole.log(i);\/\/ i \u6ca1\u6709\u5b9a\u4e49\uff0c\u62a5\u9519<\/code><\/pre>\n<ul>\n<li>\u4f5c\u7528\u57df\u94fe : \u5185\u5c42\u4f5c\u7528\u57df-&gt;\u5916\u5c42\u4f5c\u7528\u57df-&gt;...-&gt;\u5168\u5c40\u4f5c\u7528\u57df<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code>function func(){\n    for(let i=0;i&lt;3;i++){\n        console.log(i);\/\/0,1,2\n    }\n}\nfunc();\nconsole.log(i);\/\/\u62a5\u9519<\/code><\/pre>\n<ul>\n<li>\u6709\u54ea\u4e9b\u5757\u7ea7\u4f5c\u7528\u57df\n<ul>\n<li>\u51fd\u6570\u4f5c\u7528\u57df function(){}<\/li>\n<li>\u5bf9\u8c61\u672c\u8eab\u7684\u82b1\u62ec\u53f7,\u4e0d\u6784\u6210\u4f5c\u7528\u57df const person={}<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code>{\nlet age=18; \nconsole.log(age);\/\/18 \n}\nconsole.log(age);\n {}\n for(){}\n while(){}\n do{}while()\n if(){}\n switch(){}<\/code><\/pre>\n<h2>let const \u7684\u5e94\u7528 [\u4f7f\u7528 let const]<\/h2>\n<pre class=\"prettyprint linenums\" ><code>    &lt;title&gt;Title&lt;\/title&gt;\n    &lt;style&gt;\n        body{\n            padding: 50px 0 0 150px;\n        }\n        .btn{\n            width: 100px;\n            height: 100px;\n            margin-right: 20px;\n            font-size: 80px;\n            cursor: pointer;\n        }\n    &lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;button class=&quot;btn&quot;&gt;0&lt;\/button&gt;\n    &lt;button class=&quot;btn&quot;&gt;1&lt;\/button&gt;\n    &lt;button class=&quot;btn&quot;&gt;2&lt;\/button&gt;\n&lt;\/body&gt;<\/code><\/pre>\n<pre class=\"prettyprint linenums\" ><code class=\"language-js\">      \/\/1.var [3 3 3]\n        var btns=document.querySelectorAll(&#039;.btn&#039;);\n        for (var i = 0; i &lt; btns.length; i++) {\n            btns[i].addEventListener(&#039;click&#039;,function (){\n            console.log(i);\n            },false);\n        }<\/code><\/pre>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/202201071200429.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/202201071200429.png\" alt=\"\" \/><\/p><\/noscript>\n<pre class=\"prettyprint linenums\" ><code class=\"language-js\"> \/\/2.\u95ed\u5305 [0 1 2]\n        var btns=document.querySelectorAll(&#039;.btn&#039;);\n        for (var i = 0; i &lt; btns.length; i++) {\n            (function (index){\n                btns[index].addEventListener(&#039;click&#039;,function (){\n                    console.log(index);\n                },false);\n            })(i);\n        }<\/code><\/pre>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022010712022051.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022010712022051.png\" alt=\"\" \/><\/p><\/noscript>\n<pre class=\"prettyprint linenums\" ><code class=\"language-js\">   \/\/3.let \/const\n        let btns=document.querySelectorAll(&#039;.btn&#039;);\n        for (let i = 0; i &lt; btns.length; i++) {\n            btns[i].addEventListener(&#039;click&#039;,function (){\n                console.log(i);\n            },false);\n        }<\/code><\/pre>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022010711593578.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022010711593578.png\" alt=\"\" \/><\/p><\/noscript>\n<h1>\u6a21\u677f\u5b57\u7b26\u4e0e\u7bad\u5934\u51fd\u6570<\/h1>\n<h2>\u6a21\u677f\u5b57\u7b26\u4e32\u662f\u4ec0\u4e48<\/h2>\n<ul>\n<li>\n<p>\u4e00\u822c\u5b57\u7b26\u4e32: \\'alex\\' &quot;alex&quot;<\/p>\n<\/li>\n<li>\n<p>\u6a21\u677f\u5b57\u7b26\u4e32:<\/p>\n<pre class=\"prettyprint linenums\" ><code>`alex`<\/code><\/pre>\n<\/li>\n<li>\n<p>\u6a21\u677f\u5b57\u7b26\u4e32\u548c\u4e00\u822c\u5b57\u7b26\u4e32\u7684\u533a\u522b<\/p>\n<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code> const person = {\n        username: &#039;Alex&#039;,\n        age: 18,\n        sex: &#039;male&#039;\n    };\n    \/\/\u4e00\u822c\u5b57\u7b26\u4e32\n    \/\/ const info = &#039;\u6211\u7684\u540d\u5b57\u662f:&#039; + person.username + &#039;,\u6027\u522b:&#039;\n    \/\/     + person.sex + &#039;,\u4eca\u5e74&#039; + person.age + &#039;\u5c81\u4e86&#039;;\n    \/\/ console.log(info);\n    \/\/\u6a21\u677f\u5b57\u7b26\u4e32\n    const info=`\u6211\u7684\u540d\u5b57\u662f:${person.username},\u6027\u522b:${person.sex},\u4eca\u5e74${person.age}\u5c81\u4e86`;\n    console.log(info);<\/code><\/pre>\n<h2>\u6a21\u677f\u5b57\u7b26\u4e32\u7684\u6ce8\u610f\u4e8b\u9879<\/h2>\n<ul>\n<li>1.\u8f93\u51fa\u591a\u884c\u5b57\u7b26\u4e32<\/li>\n<li>2.\u8f93\u51fa`\u548c\\\u7b49\u7279\u6b8a\u5b57\u7b26,\u8f6c\u4e49\u5b57\u7b26<\/li>\n<li>3.\u6a21\u677f\u5b57\u7b26\u4e32\u7684\u6ce8\u5165\n<pre class=\"prettyprint linenums\" ><code>&lt;script&gt;\n  \/\/todo 1.\u8f93\u51fa\u591a\u884c\u5b57\u7b26\u4e32\n  \/\/\u4e00\u822c\u5b57\u7b26\u4e32\n   const info=&#039;\u7b2c 1 \u884c\\n \u7b2c 2 \u884c&#039;;\n   console.log(info);\n  \/\/\u6a21\u677f\u5b57\u7b26\u4e32\n  const info=`\u7b2c 1 \u884c\n \/\/ \u7b2c 2 \u884c`;\n console.log(info);\n  \/\/\u6a21\u677f\u5b57\u7b26\u4e32\u4e2d,\u6240\u6709\u7684\u7a7a\u683c\/\u6362\u884c\u6216\u7f29\u8fdb\u90fd\u4f1a\u88ab\u4fdd\u7559\u5728\u8f93\u51fa\u4e4b\u4e2d\n  \/\/todo 2.\u8f93\u51fa`\u548c\\\u7b49\u7279\u6b8a\u5b57\u7b26,,\u8f6c\u4e49\u5b57\u7b26\n   const info=`&#039;\\`\\\\`;\/\/ &#039;`\\\n   console.log(info);\n  \/\/todo 3.\u6a21\u677f\u5b57\u7b26\u4e32\u7684\u6ce8\u5165\n  \/\/  ${}\n  const username=&#039;alex&#039;;\n  const person={age:18,sex:&#039;male&#039;};\n  const getSex=function (sex){\n      return sex===&#039;male&#039;?&#039;\u7537&#039;:&#039;\u5973&#039;;\n  };\n  const info=`${username},${person.age+2},${getSex(person.sex)}`;\n  console.log(info);\n  \/\/\u53ea\u8981\u6700\u7ec8\u53ef\u4ee5\u5f97\u51fa\u4e00\u4e2a\u503c\u7684\u5c31\u53ef\u4ee5\u901a\u8fc7${}\u6ce8\u5165\u5230\u6a21\u677f\u5b57\u7b26\u4e32\u4e2d\n&lt;\/script&gt;<\/code><\/pre>\n<\/li>\n<\/ul>\n<h2>\u6a21\u677f\u5b57\u7b26\u4e32\u7684\u5e94\u7528[\u91cd\u8981]<\/h2>\n<pre class=\"prettyprint linenums\" ><code>&lt;html lang=&quot;en&quot;&gt;\n&lt;head&gt;\n    &lt;meta charset=&quot;UTF-8&quot;&gt;\n    &lt;title&gt;Title&lt;\/title&gt;\n    &lt;style&gt;\n        body{\n            padding: 50px 0 0 300px;\n            font-size: 22px;\n        }\n        ul{\n            padding: 0;\n        }\n        p{\n            margin-bottom: 10px;\n        }\n    &lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;p&gt;\u5b66\u751f\u4fe1\u606f\u8868&lt;\/p&gt;\n    &lt;ul id=&quot;list&quot;&gt;\n        &lt;li style=&quot;list-style: none;&quot;&gt;\u4fe1\u606f\u52a0\u8f7d\u4e2d...&lt;\/li&gt;\n    &lt;\/ul&gt;\n    &lt;script&gt;\n        \/\/\u6570\u636e Ajax\n        const students=[\n        {\n            username:&#039;Alex&#039;,\n            age:18,\n            sex:&#039;male&#039;\n        },\n        {\n            username:&#039;ZhangSan&#039;,\n            age:28,\n            sex:&#039;female&#039;\n        },\n        {\n            username:&#039;LiSi&#039;,\n            age:20,\n            sex:&#039;female&#039;\n        }\n        ];\n        const list=document.getElementById(&#039;list&#039;);\n        let html=&#039;&#039;;\n        for (let i = 0; i &lt; students.length; i++) {\n            html+=`&lt;li&gt;\u6211\u7684\u540d\u5b57\u662f:${students[i].username},${students[i].sex},${students[i].age}&lt;\/li&gt;`;\n        }\n        \/\/ console.log(html);\n        list.innerHTML=html;\n    &lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022010713185897.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022010713185897.png\" alt=\"\" \/><\/p><\/noscript>\n<h2>\u7bad\u5934\u51fd\u6570\u662f\u4ec0\u4e48<\/h2>\n<ul>\n<li>()=&gt;{};<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code class=\"language-js\">\/\/1.\u8ba4\u8bc6\u7bad\u5934\u51fd\u6570\n    const add = (x, y) =&gt; {\n        return x + y;\n    };\n    console.log(1, 1);\n    \/\/2.\u7bad\u5934\u51fd\u6570\u7684\u7ed3\u6784\n    const\/let \u51fd\u6570\u540d= \u53c2\u6570 =&gt; \u51fd\u6570\u4f53\n    \/\/3,\u5982\u4f55\u5c06\u4e00\u822c\u51fd\u6570\u6539\u5199\u6210\u7bad\u5934\u51fd\u6570\n    \/\/\u58f0\u660e\u5f62\u5f0f\n    function add(){}\n    \/\/\u58f0\u660e\u5f62\u5f0f-&gt;\u51fd\u6570\u8868\u8fbe\u5f0f\u5f62\u5f0f\n    const add=function (){};\n    \/\/\u51fd\u6570\u8868\u8fbe\u5f0f\u5f62\u5f0f-&gt;\u7bad\u5934\u51fd\u6570\n    const add=()=&gt;{};<\/code><\/pre>\n<h2>\u7bad\u5934\u51fd\u6570\u7684\u6ce8\u610f\u4e8b\u9879<\/h2>\n<pre class=\"prettyprint linenums\" ><code class=\"language-js\">\/\/1.\u5355\u4e2a\u53c2\u6570 [\u53ef\u4ee5\u7701\u7565\u5706\u62ec\u53f7]\n    const add=x=&gt;{\n       return x+1;\n     };\n    console.log(add(1));\n    \/\/2.\u65e0\u53c2\u6570\u6216\u591a\u4e2a\u53c2\u6570\u4e0d\u80fd\u7701\u7565\u5706\u62ec\u53f7\n     const add=()=&gt;{\n        return 1+1;\n     };\n     const add=(x,y)=&gt;{\n         return x+y;\n     };\n    console.log(add(1,2));\n    \/\/3.\u5355\u884c\u51fd\u6570\u4f53\n    \/\/\u5355\u884c\u51fd\u6570\u4f53\u53ef\u4ee5\u540c\u65f6\u7701\u7565{}\u548c return\n     const add=(x,y)=&gt; x+y;\n     console.log(add(1,2));\n    \/\/4.\u591a\u884c\u51fd\u6570\u4f53\u4e0d\u80fd\u518d\u5316\u7b80\u4e86\n     const add=(x,y)=&gt; {\n         const sum = x + y;\n         return sum;\n    };\n     console.log(add(1,4));\n    \/\/5.\u5355\u884c\u5bf9\u8c61\n     const add=(x,y)=&gt;{\n        return{\n            value:x+y\n         };\n     };\n    const add=(x,y)=&gt;({value:x+y});\/\/{value: 2}\n    \/\/\u5982\u679c\u7bad\u5934\u51fd\u6570\u8fd4\u56de\u5355\u884c\u5bf9\u8c61,\u53ef\u4ee5\u5728{}\u5916\u9762\u52a0\u4e0a(), \u8ba9\u6d4f\u89c8\u5668\u4e0d\u518d\u8ba4\u4e3a\u90a3\u662f\u51fd\u6570\u4f53\u7684\u82b1\u62ec\u53f7\n    \/\/ const add=(x,y)=&gt;[x,y];\n    \/\/console.log(add(1,1));\/\/(2) [1, 1]<\/code><\/pre>\n<h2>\u975e\u7bad\u5934\u51fd\u6570\u4e2d\u7684 this \u6307\u5411 [\u91cd\u8981]<\/h2>\n<ul>\n<li>\u53ea\u6709\u5728\u51fd\u6570\u8c03\u7528\u7684\u65f6\u5019 this \u6307\u5411\u624d\u786e\u5b9a,\u4e0d\u8c03\u7528\u7684\u65f6\u5019,\u4e0d\u77e5\u9053\u6307\u5411\u8c01<\/li>\n<li>this \u6307\u5411\u548c\u51fd\u6570\u5728\u54ea\u513f\u8c03\u7528\u6ca1\u5173\u7cfb,\u53ea\u548c\u8c01\u5728\u8c03\u7528\u6709\u5173,\u5c31\u6307\u5411\u8c01<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code>\/\/1.\u5168\u5c40\u4f5c\u7528\u57df\u4e2d\u7684 this \u6307\u5411\n    \/\/console.log(this);\/\/window\n    \/\/2.\u4e00\u822c\u51fd\u6570(\u975e\u7bad\u5934\u51fd\u6570)\u4e2d\u7684 this \u6307\u5411\n    \/\/&#039;use strict&#039;;\n    function add(){\n      console.log(this);\n    }\n    \/\/\u4e25\u683c\u6a21\u5f0f\u4e0b\u5c31\u6307\u5411 undefined\n    \/\/add();\/\/undefined-&gt;window(\u975e\u4e25\u683c\u6a21\u5f0f\u4e0b)\n     window.add();\n\n    const calc={\n      add:add\n    };\n    \/\/ calc.add(); \/\/calc\n\n    const adder=calc.add;\n    adder();\/\/undefined-&gt;window(\u975e\u4e25\u683c\u6a21\u5f0f\u4e0b)\n\n    document.onclick=function (){\n      console.log(this);\n    };\n    document.onclick();\/\/\u4e00\u70b9\u51fb\u6307 t#document\n\n    function Person(username){\n      this.username=username;\n      console.log(this);\n    }\n    const p=new Person(&#039;Alex&#039;);<\/code><\/pre>\n<h2>\u7bad\u5934\u51fd\u6570\u4e2d\u7684 this \u6307\u5411 [\u91cd\u8981]<\/h2>\n<pre class=\"prettyprint linenums\" ><code class=\"language-js\">      \/\/1.\u7bad\u5934\u51fd\u6570\u4e2d\u7684 this \u6307\u5411\n        \/\/\u7bad\u5934\u51fd\u6570\u6ca1\u6709\u81ea\u5df1\u7684 this\n         const calc={\n             add:()=&gt;{\n                console.log(this);\n            }\n         };\n         calc.add();\/\/window\n\n        \/\/2.\u7ec3\u4e60\n        &#039;use strict&#039;;\n        const calc={\n            add:function (){\n                \/\/this addFn\n                const adder=()=&gt;{\n                    console.log(this);\n                };\n                adder();\n            }\n        };\n        \/\/\u8c01\u8c03\u7528\u4ed6,\u4ed6\u91cc\u9762\u7684 this,\u5c31\u6307\u5411\u8c01\n        \/\/calc.add();\/\/add \u7684 this \u6307\u5411 calc\n        const addFn=calc.add;\/\/\u8d4b\u503c\n        addFn();\/\/\u65e0\u5177\u4f53\u7684\u5bf9\u8c61 undefined-&gt;window(\u975e\u4e25\u683c\u6a21\u5f0f\u4e0b)<\/code><\/pre>\n<h2>\u4e0d\u4f7f\u7528\u7bad\u5934\u51fd\u6570\u7684\u573a\u666f<\/h2>\n<ul>\n<li>1.\u4f5c\u4e3a\u6784\u9020\u51fd\u6570<\/li>\n<li>2.\u9700\u8981 this \u6307\u5411\u8c03\u7528\u5bf9\u8c61\u7684\u65f6\u5019<\/li>\n<li>3.\u9700\u8981\u4f7f\u7528 arguments \u7684\u65f6\u5019,\u6570\u7ec4<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code>\/\/1.\u4f5c\u4e3a\u6784\u9020\u51fd\u6570\n    \/\/\u7bad\u5934\u51fd\u6570\u6ca1\u6709 this\n     const Person=()=&gt;{};\n     new Person();\n\/\/2.\u9700\u8981 this \u6307\u5411\u8c03\u7528\u5bf9\u8c61\u7684\u65f6\u5019,[\u4e0d\u8981\u4f7f\u7528\u7bad\u5934\u51fd\u6570] \/\/\u56e0\u4e3a\u7bad\u5934\u51fd\u6570\u6ca1\u6709\u81ea\u5df1\u7684 this\n     document.onclick=function (){\n         console.log(this);\n     }\n      document.addEventListener(&#039;click&#039;, function(){\n         console.log(this);\/\/#document\n     },false)\n     document.addEventListener(&#039;click&#039;, ()=&gt;{\n         console.log(this);\/\/window\n     },false)\n\/\/3.\u9700\u8981\u4f7f\u7528 arguments \u7684\u65f6\u5019,\u7bad\u5934\u51fd\u6570\u4e2d\u6ca1\u6709 arguments\n    function add(){\n        console.log(arguments);\n    }\n    add(1,2);\n    \/\/Arguments(2) [1, 2, callee: \u0192, Symbol(Symbol.iterator): \u0192]\n    \/\/ const add=()=&gt; console.log(arguments);\n    \/\/ add();\n    \/\/\u5269\u4f59\u53c2\u6570<\/code><\/pre>\n<h2>\u7bad\u5934\u51fd\u6570\u7684\u5e94\u7528[\u91cd\u8981]<\/h2>\n<ul>\n<li>\u7bad\u5934\u51fd\u6570\u6ca1\u6709\u81ea\u8eab\u7684 this,\u4ed6\u7684 this \u8981\u5f80\u4e0a\u4e00\u5c42\u5bfb\u627e<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code>&lt;html lang=&quot;en&quot;&gt;\n&lt;head&gt;\n    &lt;meta charset=&quot;UTF-8&quot;&gt;\n    &lt;title&gt;Title&lt;\/title&gt;\n    &lt;style&gt;\n        body{\n            padding: 50px 0 0 250px;\n            font-size: 22px;\n            font-size: 30px;\n        }\n        #btn{\n            width: 100px;\n            height: 100px;\n            margin-right: 20px;\n            font-size: 30px;\n            cursor: pointer;\n        }\n    &lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;button id=&quot;btn&quot;&gt;\u5f00\u59cb&lt;\/button&gt;\n    &lt;span id=&quot;result&quot;&gt;0&lt;\/span&gt;\n    &lt;script&gt;\n        const btn=document.getElementById(&#039;btn&#039;);\n        const result=document.getElementById(&#039;result&#039;);\n        \/\/ const timer = {\n        \/\/   time:0,\n        \/\/   start:function (){\n        \/\/       \/\/this \u6307\u5411 timer\n        \/\/       var that=this;\n        \/\/       btn.addEventListener(&#039;click&#039;,function (){\n        \/\/           setInterval(function (){\n        \/\/               \/\/console.log(this);\/\/undefined -&gt; \u6307\u5411 window \u5bf9\u8c61[\u975e\u4e25\u683c\u6a21\u5f0f\u4e0b]\n        \/\/               \/\/ this.time++;\n        \/\/               \/\/ result.innerHTML=this.time;\n        \/\/               that.time++;\n        \/\/               result.innerHTML=that.time;\n        \/\/           },1000);\n        \/\/       },false);\n        \/\/   }\n        \/\/ };\n        const timer = {\n            time:0,\n            start:function (){\n                \/\/this \u6307\u5411 timer\n                btn.addEventListener(\n                    &#039;click&#039;,\n                    ()=&gt;{\/\/\u6307\u5411 timer \u7684 this\n                    \/\/this\n                    setInterval( ()=&gt;{\/\/\u6307\u5411\u4e0a\u4e00\u5c42\u7684 this\n                        \/\/console.log(this);\n                        this.time++;\n                        result.innerHTML=this.time;\n                    },1000);\n                },false);\n            }\n        };\n        timer.start();\n    &lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022010715220632.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022010715220632.png\" alt=\"\" \/><\/p><\/noscript>\n<h2>\u603b\u7ed3<\/h2>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022010715233828.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022010715233828.png\" alt=\"\" \/><\/p><\/noscript>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022010715241937.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022010715241937.png\" alt=\"\" \/><\/p><\/noscript>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022010715245383.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022010715245383.png\" alt=\"\" \/><\/p><\/noscript>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022010715252561.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022010715252561.png\" alt=\"\" \/><\/p><\/noscript>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022010715255775.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/2022010715255775.png\" alt=\"\" \/><\/p><\/noscript>\n<h1>\u89e3\u6784\u8d4b\u503c<\/h1>\n<h2>\u89e3\u6784\u8d4b\u503c\u662f\u4ec0\u4e48<\/h2>\n<pre class=\"prettyprint linenums\" ><code>      \/\/1.\u8ba4\u8bc6\u89e3\u6784\u8d4b\u503c\n        \/\/ const arr=[1,2,3];\n        \/\/ const a=arr[0];\n        \/\/ const b=arr[1];\n        \/\/ const c=arr[2];\n        \/\/ console.log(a,b,c);\/\/1 2 3\n        const [a,b,c]=[1,2,3];\n        console.log(a,b,c);\/\/1 2 3\n        \/\/2.\u4ec0\u4e48\u662f\u89e3\u6784\u8d4b\u503c\n        \/\/\u89e3\u6790\u67d0\u4e00\u6570\u636e\u7684\u7ed3\u6784,\u5c06\u6211\u4eec\u60f3\u8981\u7684\u4e1c\u897f\u63d0\u53d6\u51fa\u6765,\u8d4b\u503c\u7ed9\u53d8\u91cf\u6216\u5e38\u91cf<\/code><\/pre>\n<h2>\u6570\u7ec4\u89e3\u6784\u8d4b\u503c\u7684\u539f\u7406<\/h2>\n<ul>\n<li>\u6a21\u5f0f(\u7ed3\u6784)\u5339\u914d<\/li>\n<li>\u7d22\u5f15\u503c\u76f8\u540c\u7684\u5b8c\u6210\u8d4b\u503c<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code>const[a,[,,b],c]=[1,[2,4,5],3];\nconsole.log(a,b,c);\/\/1 5 3<\/code><\/pre>\n<h2>\u6570\u7ec4\u89e3\u6784\u8d4b\u503c\u7684\u9ed8\u8ba4\u503c<\/h2>\n<pre class=\"prettyprint linenums\" ><code>       \/\/1.\u9ed8\u8ba4\u503c\u7684\u57fa\u672c\u7528\u6cd5\n         const [a,b]=[];\n         const [a,b]=[undefined,undefined];\n         const [a=1,b=2]=[];\n         console.log(a,b);\n        \/\/2.\u9ed8\u8ba4\u503c\u7684\u751f\u6548\u6761\u4ef6\n        \/\/\u53ea\u6709\u5f53\u4e00\u4e2a\u6570\u7ec4\u6210\u5458\u4e25\u683c\u7b49\u4e8e(===)undefined \u65f6,\u5bf9\u5e94\u7684\u9ed8\u8ba4\u503c\u624d\u4f1a\u751f\u6548\n        const [a=1,b=2]=[3,0];\/\/3 0\n        const [a=1,b=2]=[3,null];\/\/3 null\n        const [a=1,b=2]=[3];\/\/3 2\n         console.log(a,b);\n        \/\/3.\u9ed8\u8ba4\u503c\u8868\u8fbe\u5f0f\n        \/\/\u5982\u679c\u9ed8\u8ba4\u503c\u662f\u8868\u8fbe\u5f0f,\u9ed8\u8ba4\u503c\u8868\u8fbe\u5f0f\u662f\u60f0\u6027\u6c42\u503c\u7684\n        const func=()=&gt;{\n            console.log(&#039;\u6211\u88ab\u6267\u884c\u4e86&#039;);\n            return 2;\n        };\n        \/\/const [x=func()]=[1];\/\/1\n        const [x=func()]=[];\/\/\u6211\u88ab\u6267\u884c\u4e86 2\n        console.log(x);<\/code><\/pre>\n<h2>\u6570\u7ec4\u89e3\u6784\u8d4b\u503c\u7684\u5e94\u7528<\/h2>\n<pre class=\"prettyprint linenums\" ><code>   &lt;p&gt;123&lt;\/p&gt;\n    &lt;p&gt;321&lt;\/p&gt;\n    &lt;p&gt;34567&lt;\/p&gt;\n    &lt;script&gt;\n        \/\/1.\u5e38\u89c1\u7684\u7c7b\u6570\u7ec4\u7684\u89e3\u6784\u8d4b\u503c\n        \/\/arguments\n        function func(){\n             console.log(arguments);\n             console.log(arguments.push);\/\/undefined \u53ea\u662f\u4e2a\u7c7b\u6570\u7ec4\n          const [a,b]=arguments;\n          console.log(a,b);\n        }\n         func();\n        func(1,2);\/\/1 2\n       \/\/NodeList \u8282\u70b9\u5217\u8868\n      console.log(document.querySelectorAll(&#039;p&#039;));\/\/\u8f93\u51fa\u5185\u5bb9\/\/NodeList(3) [p,p,p]\n         const [p1,p2,p3]=document.querySelectorAll(&#039;p&#039;);\n         console.log(p1,p2,p3);<\/code><\/pre>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/202208072015566.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2022\/01\/202208072015566.png\" alt=\"\" \/><\/p><\/noscript>\n<pre class=\"prettyprint linenums\" ><code>\/\/2.\u51fd\u6570\u53c2\u6570\u7684\u89e3\u6784\u8d4b\u503c\n const array=[1,1];\n \/\/ const add=arr=&gt;arr[0]+arr[1];\n const add=([x=0,y=0])=&gt;x+y;\/\/[x,y]=[1,1]\n console.log(add(array));\/\/2\n console.log(add([]));\/\/0\n\/\/3.\u4ea4\u6362\u53d8\u91cf\u7684\u503c\nlet x=1;\nlet y=2;\n\/\/ let tmp=x;\n\/\/ x=y;\n\/\/ y=tmp;\n\/\/ console.log(x,y);\/\/2 1\n[x,y]=[y,x];\nconsole.log(x,y);\/\/2 1<\/code><\/pre>\n<h2>\u5bf9\u8c61\u89e3\u6784\u8d4b\u503c\u7684\u539f\u7406<\/h2>\n<pre class=\"prettyprint linenums\" ><code> \/\/1.\u6a21\u5f0f(\u7ed3\u6784)\u5339\u914d\n        {}={}\n\/\/2.\u5c5e\u6027\u540d\u76f8\u540c\u7684\u5b8c\u6210\u8d4b\u503c\n         const {age,username}={username:&#039;Alex&#039;,age:18}\n         const {age:age,username:username}={username:&#039;Alex&#039;,age:18}\n         console.log(age,username);\n        \/\/\u8d77\u522b\u540d\n        const {age:age,username:uname}={username:&#039;Alex&#039;,age:18}\n        console.log(age,uname);<\/code><\/pre>\n<h2>\u5bf9\u8c61\u89e3\u6784\u8d4b\u503c\u7684\u6ce8\u610f\u4e8b\u9879<\/h2>\n<ul>\n<li>\u5bf9\u8c61\u89e3\u6784\u8d4b\u503c\u7684\u9ed8\u8ba4\u503c<\/li>\n<li>\u5c06\u4e00\u4e2a\u5df2\u7ecf\u58f0\u660e\u7684\u53d8\u91cf\u7528\u4e8e\u89e3\u6784\u8d4b\u503c<\/li>\n<li>\u53ef\u4ee5\u53d6\u5230\u7ee7\u627f\u7684\u5c5e\u6027<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code> \/\/1.\u9ed8\u8ba4\u503c\u7684\u751f\u6548\u6761\u4ef6\n        \/\/\u5bf9\u8c61\u7684\u5c5e\u6027\u503c\u4e25\u683c\u7b49\u4e8e undefined \u65f6,\u5bf9\u5e94\u7684\u9ed8\u8ba4\u503c\u624d\u4f1a\u751f\u6548\n        const {username=&#039;zhangsan&#039;,age=0}={username:&#039;alec&#039;};\/\/age:undefined\n        console.log(username,age);\/\/alec 0\n\/\/2.\u9ed8\u8ba4\u503c\u8868\u8fbe\u5f0f\n        \/\/\u5982\u679c\u9ed8\u8ba4\u503c\u662f\u8868\u8fbe\u5f0f,\u9ed8\u8ba4\u503c\u8868\u8fbe\u5f0f\u662f\u60f0\u6027\u6c42\u503c\u7684\n\/\/3.\u5c06\u4e00\u4e2a\u5df2\u7ecf\u58f0\u660e\u7684\u53d8\u91cf\u7528\u4e8e\u89e3\u6784\u8d4b\u503c\n        \/\/\u5982\u679c\u5c06\u4e00\u4e2a\u5df2\u7ecf\u58f0\u660e\u7684\u53d8\u91cf\u7528\u4e8e\u5bf9\u8c61\u7684\u89e3\u6784\u8d4b\u503c,\u6574\u4e2a\u8d4b\u503c\u9700\u5728\u5706\u62ec\u53f7\u4e2d\u8fdb\u884c\n        \/\/ let {x}={x:1};\n        \/\/ console.log(x);\/\/1\n         let x=2;\n        ({x}={x:1});\n        \/\/ [x]=[1];\n        console.log(x);\/\/1\n        \/\/4.\u53ef\u4ee5\u53d6\u5230\u7ee7\u627f\u7684\u5c5e\u6027\n        const {a=1}={};\n        console.log(a);\/\/1\n        const {toString}={};\n        console.log(toString);\/\/\u51fd\u6570\u0192 toString()\n        \/\/ Object.prototype ,,toString \u7ee7\u627f\u5bf9\u8c61 Object\n        console.log(Object.prototype);\n        console.log({});<\/code><\/pre>\n<h2>\u5bf9\u8c61\u89e3\u6784\u8d4b\u503c\u7684\u5e94\u7528<\/h2>\n<pre class=\"prettyprint linenums\" ><code>\/\/1.\u51fd\u6570\u53c2\u6570\u7684\u89e3\u6784\u8d4b\u503c\n        \/\/ const logPersonInfo=user=&gt;console.log(user.username,user.age);\n        const logPersonInfo=({age=0,username=&#039;hkj&#039;})=&gt;console.log(username,age);\n        \/\/ logPersonInfo({username:&#039;alex&#039;,age:18});\/\/alex 18\n        logPersonInfo({});\/\/hkj 0\n        \/\/2.\u590d\u6742\u7684\u5d4c\u5957\n        const obj={\n            x:1,\n            y:[2,3,4],\n            z:{\n                a:5,\n                b:6\n            }\n        };\n        \/\/ const {x,y,z}=obj;\n        \/\/ console.log(x,y,z);\n        const {\n            y,\n            y:[,yy],\n            z,\n            z:{\n                b:b\n            }\n        }=obj;\/\/[,yy]=[2,3,4]\n        console.log(yy,y,z,b);\/\/3 (3)[2, 3, 4] {a: 5, b: 6} 6<\/code><\/pre>\n<h2>\u5176\u5b83\u6570\u636e\u7c7b\u578b\u7684\u89e3\u6784\u8d4b\u503c<\/h2>\n<pre class=\"prettyprint linenums\" ><code> \/\/1.\u5b57\u7b26\u4e32\u7684\u89e3\u6784\u8d4b\u503c\n        \/\/&#039;&#039;=&#039;hello&#039; x\n        \/\/\u6570\u7ec4\u5f62\u5f0f\u7684\u89e3\u6784\u8d4b\u503c\n         const [a,b,,,c]=&#039;hello&#039;;\n         console.log(a,b,c);\/\/h e o\n        \/\/\u5bf9\u8c61\u5f62\u5f0f\u7684\u89e3\u6784\u8d4b\u503c\n         const {0:a,1:b,length}=&#039;hello&#039;;\n         console.log(a,b,length);\/\/h e 5\n         console.log(&#039;hello&#039;.length);\/\/5\n        \/\/\u5b57\u7b26\u4e32\u65e2\u53ef\u4ee5\u6309\u6570\u7ec4\u5f62\u5f0f\u6765\u89e3\u6784\u8d4b\u503c,\u4e5f\u53ef\u4ee5\u6309\u5bf9\u8c61\u5f62\u5f0f\u6765\u89e3\u6784\u8d4b\u503c\n        \/\/2.\u6570\u503c\u548c\u5e03\u5c14\u503c\u7684\u89e3\u6784\u8d4b\u503c\n        \/\/\u5148\u5c06\u7b49\u53f7\u53f3\u8fb9\u7684\u503c\u8f6c\u4e3a\u5bf9\u8c61\n         console.log(new Number(123));\n         const  {a=1,toString}=123;\n         console.log(a,toString);\/\/1 \u0192 toString() { [native code] }\n        \/\/\u5e03\u5c14\u503c\n        const  {b=2,toString}=true;\n        console.log(b,toString);\/\/2 \u0192 toString() { [native code] }\n        \/\/3.undefined \u548c null \u7684\u89e3\u6784\u8d4b\u503c\n        \/\/\u7531\u4e8e undefined \u548c null \u65e0\u6cd5\u8f6c\u4e3a\u5bf9\u8c61,\u6240\u4ee5\u5bf9\u5b83\u4eec\u8fdb\u884c\u89e3\u6784\u8d4b\u503c,\u90fd\u4f1a\u62a5\u9519\n        \u5bf9\u8c61\u5f62\u5f0f\n         const {toString}=undefined;\n         const {toString}=null;<\/code><\/pre>\n<h1>\u5bf9\u8c61\u5b57\u9762\u770b\u7684\u589e\u5f3a\u4e0e\u51fd\u6570\u53c2\u6570\u9ed8\u8ba4\u503c<\/h1>\n<h2>\u5c5e\u6027\u548c\u65b9\u6cd5\u7684\u7b80\u6d01\u8868\u793a\u6cd5[\u7ecf\u5e38\u4f7f\u7528]<\/h2>\n<pre class=\"prettyprint linenums\" ><code>  \/\/1.\u5bf9\u8c61\u5b57\u9762\u91cf\u662f\u4ec0\u4e48\n    \/\/\u5b9e\u4f8b\u5316\u6784\u9020\u51fd\u6570\u751f\u6210\u5bf9\u8c61\n     const person=new Object();\n     person.age=18;\n     person.speak=function (){};\n    \/\/\u5bf9\u8c61\u5b57\u9762\u91cf [\u7528\u7684\u591a]\n    const person={\n     age:18,\n      speak:function (){}\n    };\n    \/\/2.\u5c5e\u6027\u7684\u7b80\u6d01\u8868\u793a\u6cd5\n    \/\/\u952e\u540d\u548c\u53d8\u91cf\u6216\u5e38\u91cf\u540d\u4e00\u6837\u7684\u65f6\u5019,\u53ef\u4ee5\u53ea\u5199\u4e00\u4e2a\n     const age=18;\n    const person={\n       \/\/age:age,\n       age\n     };\n     console.log(person);\/\/{age: 18}\n    \/\/3.\u65b9\u6cd5\u7684\u7b80\u6d01\u8868\u793a\u6cd5\n    \/\/\u65b9\u6cd5\u53ef\u4ee5\u7701\u7565\u5192\u53f7\u548c function \u5173\u952e\u5b57\n    const person = {\n        \/\/ speak:function(){}\n        speak() {\n        }\n    };\n    console.log(person);\/\/{speak: \u0192}<\/code><\/pre>\n<h2>\u65b9\u62ec\u53f7\u8bed\u6cd5[\u4e86\u89e3]<\/h2>\n<pre class=\"prettyprint linenums\" ><code>       \/\/1.\u65b9\u62ec\u53f7\u8bed\u6cd5\u7684\u7528\u6cd5\n        const prop=&#039;age&#039;;\n        const person={};\n         person.prop=18;\u4e0d\u53ef\u4ee5\u4f7f\u7528\u70b9\u8bed\u6cd5\n        person[prop]=18;\n        \/\/\u65b9\u62ec\u53f7\u8bed\u6cd5\u53ef\u4ee5\u5199\u5728\u5bf9\u8c61\u5b57\u9762\u91cf\u4e2d\n         const person={\n             [prop]:18\n         };\n         console.log(person);\n      \/\/2.\u65b9\u62ec\u53f7\u4e2d\u53ef\u4ee5\u653e\u4ec0\u4e48\n        \/\/${}\n        \/\/[\u503c\u6216\u901a\u8fc7\u8ba1\u7b97\u53ef\u4ee5\u5f97\u5230\u503c\u7684(\u8868\u8fbe\u5f0f)]\n         const prop=&#039;age&#039;;\n         const func=()=&gt;&#039;age2&#039;;\n         const person ={\n          \/\/ [prop]:18\n           \/\/ [func()]:18\n           \/\/   [&#039;sex&#039;]:&#039;male&#039;\n             [&#039;s&#039;+&#039;ex&#039;]:&#039;male&#039;\n         };\n        console.log(person);\n\/\/3.\u65b9\u62ec\u53f7\u8bed\u6cd5\u548c\u70b9\u8bed\u6cd5\u7684\u533a\u522b\n        \/\/\u70b9\u8bed\u6cd5\u662f\u65b9\u62ec\u53f7\u8bed\u6cd5\u7684\u7279\u6b8a\u5f62\u5f0f\n        const person={};\n        \/\/ person.age \u7b49\u4ef7\u4e8e person[&#039;age&#039;]\n        \/\/\u5408\u6cd5\u6807\u8bc6\u7b26:\u5c5e\u6027\u540d\u7531\u6570\u5b57.\u5b57\u6bcd.\u4e0b\u5212\u7ebf\u4ee5\u53ca$\u6784\u6210,\u5e76\u4e14\u6570\u5b57\u8fd8\u4e0d\u80fd\u6253\u5934 \u7684\u65f6\u5019\u53ef\u4ee5\u4f7f\u7528\u70b9\u8bed\u6cd5\n        \/\/ age18_$\u221a \u5408\u6cd5\u6807\u8bc6\u7b26\u53ef\u4ee5\u7528\u6765\u4f5c\u4e3a\u53d8\u91cf\u6216\u5e38\u91cf\u540d\n        \/\/18age \u00d7\n        \/\/\u5f53\u4f60\u7684\u5c5e\u6027\u6216\u65b9\u6cd5\u540d\u662f\u5408\u6cd5\u6807\u8bc6\u7b26\u65f6,\u53ef\u4ee5\u4f7f\u7528\u70b9\u8bed\u6cd5,\u5176\u4ed6\u60c5\u51b5\u4e0b\u8bf7\u4f7f\u7528\u65b9\u62ec\u53f7\u8bed\u6cd5<\/code><\/pre>\n<h2>\u51fd\u6570\u53c2\u6570\u7684\u9ed8\u8ba4\u503c\u662f\u4ec0\u4e48<\/h2>\n<pre class=\"prettyprint linenums\" ><code> \/\/1.\u8ba4\u8bc6\u51fd\u6570\u53c2\u6570\u7684\u9ed8\u8ba4\u503c\n      \/\/\u8c03\u7528\u51fd\u6570\u7684\u65f6\u5019\u4f20\u53c2\u4e86,\u5c31\u7528\u4f20\u9012\u7684\u53c2\u6570;\u5982\u679c\u6ca1\u4f20\u53c2,\u5c31\u7528\u9ed8\u8ba4\u503c\n      multiply(2,1);\n      multiply(2);\n      \/\/2.\u51fd\u6570\u53c2\u6570\u9ed8\u8ba4\u503c\u7684\u57fa\u672c\u7528\u6cd5\n      \/\/(1)\n       const multiply=(x,y)=&gt;{\n          if(typeof y===&#039;undefined&#039;){\n               y=1;\n           }\n           return x*y;\n     }\n      \/\/(2)\n      const multiply=(x,y=1)=&gt; x*y;\n      console.log(multiply(2,2));<\/code><\/pre>\n<h2>\u51fd\u6570\u53c2\u6570\u9ed8\u8ba4\u503c\u7684\u6ce8\u610f\u4e8b\u9879<\/h2>\n<pre class=\"prettyprint linenums\" ><code> \/\/1.\u9ed8\u8ba4\u503c\u7684\u751f\u6548\u6761\u4ef6\n      \/\/\u4e0d\u4f20\u53c2\u6570,\u6216\u8005\u660e\u786e\u7684\u4f20\u9012 undefined \u4f5c\u4e3a\u53c2\u6570,\u53ea\u6709\u8fd9\u4e24\u79cd\u60c5\u51b5\u4e0b,\u9ed8\u8ba4\u503c\u624d\u4f1a\u751f\u6548\n       const multiply=(x,y=1)=&gt; x*y;\n       console.log(multiply(2,0));\/\/0\n       console.log(multiply(2,null));\/\/0\n       console.log(multiply(2,undefined));\/\/2\n       console.log(multiply(2));\/\/2\n      \/\/2.\u9ed8\u8ba4\u503c\u8868\u8fbe\u5f0f\n      \/\/\u5982\u679c\u9ed8\u8ba4\u503c\u662f\u8868\u8fbe\u5f0f,\u9ed8\u8ba4\u503c\u8868\u8fbe\u5f0f\u662f\u60f0\u6027\u6c42\u503c\u7684\n      \/\/3.\u8bbe\u7f6e\u9ed8\u8ba4\u503c\u7684\u5c0f\u6280\u5de7\n      \/\/\u51fd\u6570\u53c2\u6570\u7684\u9ed8\u8ba4\u503c,\u6700\u597d\u4ece\u53c2\u6570\u5217\u8868\u7684\u53f3\u8fb9\u5f00\u59cb\u8bbe\u7f6e\n      const multiply=(x=1,y)=&gt; x*y;\n      console.log(multiply(undefined,2))<\/code><\/pre>\n<h2>\u51fd\u6570\u53c2\u6570\u9ed8\u8ba4\u503c\u7684\u5e94\u7528[\u91cd\u70b9]<\/h2>\n<pre class=\"prettyprint linenums\" ><code>  \/\/1.\u63a5\u6536\u5f88\u591a\u53c2\u6570\u7684\u65f6\u5019\n      \/* \u5b9e\u9645\u5f00\u53d1\u4e2d,\u4e0d\u7528\u8fd9\u5199\u6cd5\n      const logUser=(username=&#039;zhangsan&#039;,age=0,sex=&#039;male&#039;)=&gt;console.log(username,age,sex)\n      logUser(&#039;Al&#039;,19,&#039;male&#039;);\n      logUser()*\/\n\n      \/\/2.\u63a5\u6536\u4e00\u4e2a\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\n      \/* \u00d7\u00d7\u00d7\u00d7 const logUser=options=&gt;console.log(options.username,options.age,options.sex);\n        logUser({\n        username:&#039;al&#039;,\n        age:19,\n        sex:&#039;male&#039;\n      })*\/\n      \/\/\u6ce8\u610f: options={}  &lt;=&gt; {username=&#039;zhangsan&#039;,age=0,sex=&#039;male&#039;}={} \u5bf9\u4e00\u4e2a\u7a7a\u5bf9\u8c61\u6765\u89e3\u6784\n      const logUser=({username=&#039;zhangsan&#039;,age=0,sex=&#039;male&#039;}={})=&gt;console.log(username,age,sex)\n      \/\/ logUser({username:&#039;al&#039;})\/\/al 0 male\n      \/\/ logUser({}) \/\/zhangsan 0 male\n      logUser(); \/\/zhangsan 0 male \/\/{username=&#039;zhangsan&#039;,age=0,sex=&#039;male&#039;}=undefined<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>ES6 \u7b80\u4ecb \u6b27\u6d32\u8ba1\u7b97\u673a\u5236\u9020\u5546\u534f\u4f1a \u6807\u51c6\u5316\u7ec4\u7ec7 ECMAScript=\u7531 ECMA \u8fd9\u4e2a\u6807\u51c6\u5316\u7ec4\u7ec7\u5236\u5b9a\u7684\u4e00\u4e2a\u8bed [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-2535","post","type-post","status-publish","format-standard","hentry","category-web"],"_links":{"self":[{"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/posts\/2535","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2535"}],"version-history":[{"count":44,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/posts\/2535\/revisions"}],"predecessor-version":[{"id":4159,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/posts\/2535\/revisions\/4159"}],"wp:attachment":[{"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}