{"id":1905,"date":"2023-03-25T14:26:38","date_gmt":"2023-03-25T06:26:38","guid":{"rendered":""},"modified":"2023-03-25T14:26:38","modified_gmt":"2023-03-25T06:26:38","slug":"ES6 \u8bed\u6cd5","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/1905.html","title":{"rendered":"ES6 \u8bed\u6cd5"},"content":{"rendered":"


\n <\/head>
\n <\/p>\n

\n

ES6 \u8bed\u6cd5<\/h1>\n<\/p><\/div>\n

ES6 \u8bed\u6cd5<\/h2>\n
\n \u8bed\u6cd5\u662f\u5b9a\u4e49\u7b26\u53f7\u6392\u5217\u7684\u89c4\u5219\u96c6\u3002\u6bcf\u4e2a\u8bed\u8a00\u89c4\u8303\u90fd\u6709\u5176\u8bed\u6cd5\u3002\u8bed\u6cd5\u9002\u7528\u4e8e\u6587\u6863\u8868\u793a\u6e90\u4ee3\u7801\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u4e5f\u9002\u7528\u4e8e\u6587\u6863\u63cf\u8ff0\u6e90\u4ee3\u7801\u7684\u6807\u8bb0\u8bed\u8a00\n <\/div>\n
\n JavaScript \u4e2d\u7684\u7a0b\u5e8f\u5305\u62ec:\n <\/div>\n
\n \u6587\u5b57: \u6587\u5b57\u53ef\u4ee5\u5b9a\u4e49\u4e3a\u8868\u793a\u6e90\u4ee3\u7801\u4e2d\u56fa\u5b9a\u503c\u7684\u7b26\u53f7\u3002\u901a\u5e38\uff0c\u6587\u5b57\u7528\u4e8e\u521d\u59cb\u5316\u53d8\u91cf\u3002\u5728\u4e0b\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u60a8\u53ef\u4ee5\u770b\u5230\u6587\u5b57\u7684\u4f7f\u7528\uff0c\u5176\u4e2d 1 \u8868\u793a\u6574\u6570\u6587\u5b57\uff0c\u800c\u5b57\u7b26\u4e32 \"hello\" \u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u6587\u5b57\u3002\n <\/div>\n
\n
int <\/span>x = 1;\nstring str = \"hello\"<\/span>;<\/pre>\n

<\/code>\n <\/div>\n

\n \u53d8\u91cf: \u53d8\u91cf\u662f\u7531\u5185\u5b58\u5730\u5740\u6807\u8bc6\u7684\u5b58\u50a8\u4f4d\u7f6e\u3002\u53d8\u91cf\u662f\u5b58\u50a8\u7a0b\u5e8f\u503c\u7684\u5185\u5b58\u5757\u7684\u540d\u79f0\u3002\u53d8\u91cf\u7684\u540d\u79f0\u662f\u5f15\u7528\u5b58\u50a8\u503c\u7684\u6807\u51c6\u65b9\u5f0f\u3002\n <\/div>\n
\n \u5173\u952e\u5b57: \u5728\u8ba1\u7b97\u673a\u7f16\u7a0b\u4e2d\uff0c\u5173\u952e\u5b57\u662f\u5177\u6709\u7279\u5b9a\u8bed\u5883\u4e0b\u7684\u7279\u6b8a\u542b\u4e49\u3002\u5b83\u4e0d\u80fd\u7528\u4f5c\u53d8\u91cf\u540d\u3001\u51fd\u6570\u540d\u6216\u6807\u7b7e\u7b49\u6807\u8bc6\u7b26\u3002\n <\/div>\n
\n \u8fd0\u7b97\u7b26: \u8fd0\u7b97\u7b26\u662f\u5b9a\u4e49\u64cd\u4f5c\u6570\u5904\u7406\u7684\u7b26\u53f7\u3002\u8fd0\u7b97\u7b26\u7684\u4e00\u4e9b\u5e38\u89c1\u793a\u4f8b\u5305\u62ec\u7b97\u672f(\u52a0\u6cd5\u4e0e +)\uff0c\u903b\u8f91\u8fd0\u7b97\u7b26(\u5982AND \u6216 &&)\u7b49\n <\/div>\n
\n \u6ce8\u91ca: \u6ce8\u91ca\u662f\u8ba1\u7b97\u673a\u7a0b\u5e8f\u6e90\u4ee3\u7801\u4e2d\u7a0b\u5e8f\u5458\u53ef\u8bfb\u7684\u6ce8\u91ca(\u989d\u5916\u4fe1\u606f)\u3002\u6dfb\u52a0\u4e86\u6ce8\u91ca\u4ee5\u4f7f\u6e90\u4ee3\u7801\u6613\u4e8e\u4eba\u7c7b\u7406\u89e3\u3002\u6ce8\u91ca\u63d0\u9ad8\u4e86\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\uff0c\u4f46\u88ab\u7f16\u8bd1\u5668\u548c\u89e3\u91ca\u5668\u5ffd\u7565\u4e86\u3002\n <\/div>\n
\n JavaScript \u652f\u6301\u4ee5\u4e0b\u4e24\u79cd\u7c7b\u578b\u7684\u6ce8\u91ca:\n <\/div>\n

\u591a\u884c\u6ce8\u91ca: \u8fd9\u4e9b\u6ce8\u91ca\u7528\u4e8e\u5bf9\u591a\u884c\u8fdb\u884c\u6ce8\u91ca\u3002
\u4f8b\u5982: \/*\u8fd9\u662f\u591a\u884c\u6ce8\u91ca\u7684\u4e00\u4e2a
\u793a\u4f8b\u884c\u6ce8\u91ca*\/.<\/span>
\n \u5355\u884c\u6ce8\u91ca: \u8fd9\u4e9b\u6ce8\u91ca\u7528\u4e8e\u5bf9\u5355\u884c\u8fdb\u884c\u6ce8\u91ca\u3002
\u4f8b\u5982: \/\/\u5b83\u662f\u5355\u884c\u6ce8\u91ca\u3002<\/span> <\/p>\n

\n \u6807\u8bc6\u7b26: \u6807\u8bc6\u7b26\u662f\u7a0b\u5e8f\u4e2d\u5143\u7d20\u7684\u540d\u79f0\uff0c\u4f8b\u5982\u51fd\u6570\u3001\u53d8\u91cf\u7b49\u3002\u6807\u8bc6\u7b26\u6709\u4e00\u4e9b\u89c4\u5219\u5982\u4e0b:\n <\/div>\n

\u6807\u8bc6\u7b26\u4e0d\u5305\u542b\u4efb\u4f55\u7279\u6b8a\u7b26\u53f7\uff0c\u7f8e\u5143\u7b26\u53f7($) \u6216\u4e0b\u5212\u7ebf (_) \u9664\u5916\u3002<\/span>
\n \u6807\u8bc6\u7b26\u540d\u79f0\u4e0d\u80fd\u662f\u5173\u952e\u5b57\u3002<\/span>
\n \u6807\u8bc6\u7b26\u5305\u62ec\u5b57\u7b26\u548c\u6570\u5b57\u3002\u4f46\u662f\u6807\u8bc6\u7b26\u7684\u540d\u79f0\u4e0d\u80fd\u4ee5\u6570\u5b57\u5f00\u5934\u3002<\/span>
\n \u6807\u8bc6\u7b26\u533a\u5206\u5927\u5c0f\u5199\u4e14\u4e0d\u5305\u542b\u7a7a\u683c\u3002<\/span> <\/p>\n

\n \u4f8b\u5982: \u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u60a8\u5c06\u770b\u5230\u6807\u8bc6\u7b26\u7684\u6709\u6548\u548c\u65e0\u6548\u58f0\u660e\u7684\u793a\u4f8b\u3002\n <\/div>\n
\n \u6709\u6548\u6807\u8bc6\u7b26\u793a\u4f8b: \u7528\u6237\u540d\u3001\u7528\u6237\u540d\u3001name14\u3001$name\u3002\n <\/div>\n
\n \u65e0\u6548\u6807\u8bc6\u7b26\u793a\u4f8b: [\u7535\u5b50\u90ae\u4ef6\u4fdd\u62a4]\uff0c\u7528\u6237\u540d\uff0c\u7528\u6237\u540d\uff0c14name\u3002\n <\/div>\n

\u6362\u884c\u7b26\u548c\u7a7a\u683c<\/h2>\n
\n ECMAScript \u4f1a\u5ffd\u7565\u7a0b\u5e8f\u4e2d\u51fa\u73b0\u7684\u5236\u8868\u7b26\u3001\u7a7a\u683c\u548c\u6362\u884c\u7b26\u3002\u6211\u4eec\u53ef\u4ee5\u5728\u7a0b\u5e8f\u4e2d\u8f7b\u677e\u4f7f\u7528\u5236\u8868\u7b26\u3001\u7a7a\u683c\u548c\u6362\u884c\u7b26\uff0c\u5e76\u4e14\u53ef\u4ee5\u4ee5\u53ef\u9760\u7684\u65b9\u5f0f\u81ea\u7531\u5730\u5bf9\u7a0b\u5e8f\u8fdb\u884c\u683c\u5f0f\u5316\u548c\u7f29\u8fdb\uff0c\u8fd9\u589e\u52a0\u4e86\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u5e76\u4f7f\u5176\u6613\u4e8e\u7406\u89e3\u3002\n <\/div>\n
\n \u6709JavaScript \u53c2\u8003\u6587\u732e\u4e2d\u7684\u4e00\u4e9b\u91cd\u8981\u70b9\u5b9a\u4e49\u5982\u4e0b:\n <\/div>\n

JavaScript \u548c Camel Case<\/h2>\n
\n JavaScript \u7a0b\u5e8f\u5458\u5e94\u8be5\u4f7f\u7528 \u5c0f\u9a7c\u5cf0(\u4ee5\u5c0f\u5199\u5b57\u6bcd\u5f00\u5934)\u3002\n <\/div>\n
\n \u4f8b\u5982 userName\u3001firstName\u3001cityName \u7b49\u3002\n <\/div>\n
\n \u6ce8\u610f: <\/span>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cJavaScript \u4e2d\u4e0d\u5141\u8bb8\u4f7f\u7528\u8fde\u5b57\u7b26\uff0c\u56e0\u4e3a\u8fde\u5b57\u7b26\u662f\u4e3a\u51cf\u6cd5\u4fdd\u7559\u7684\u3002\n <\/div>\n

JavaScript \u533a\u5206\u5927\u5c0f\u5199<\/h2>\n
\n JavaScript \u4e2d\u7684\u6807\u8bc6\u7b26\u533a\u5206\u5927\u5c0f\u5199\u3002\u8fd9\u610f\u5473\u7740JavaScript\u4e2d\u7684\u5927\u5199\u5b57\u7b26\u548c\u5c0f\u5199\u5b57\u7b26\u662f\u4e0d\u540c\u7684\u3002\n <\/div>\n
\n \u4f8b\u5982:\n <\/div>\n
\n \u7528\u6237\u540d\u548c userName \u90fd\u662f JavaScript \u4e2d\u7684\u4e0d\u540c\u53d8\u91cf\n <\/div>\n
\n
var <\/span>username, userName;\nusername = \"Anil\"<\/span>;\nuserName = \"Sunil\"<\/span>;<\/pre>\n

<\/code>\n <\/div>\n

\u5206\u53f7\u662f\u53ef\u9009\u7684<\/h2>\n
\n \u5206\u53f7\u7684\u4f7f\u7528\u5728 JavaScript \u4e2d\u662f\u53ef\u9009\u7684\u3002\u4f46\u662f\u5982\u679c\u4e00\u884c\u6709\u591a\u4e2a\u8bed\u53e5(\u6307\u4ee4\u5e8f\u5217)\uff0c\u90a3\u4e48\u8fd9\u4e9b\u8bed\u53e5\u5fc5\u987b\u7528\u5206\u53f7\u5206\u9694\u3002\n <\/div>\n
\n \u4f8b\u5982:\n <\/div>\n
\n
console.log<\/span>(\"hello world\"<\/span>)\nconsole.log<\/span>(\"Welcome to lidihuo.com\"<\/span>); console.log<\/span>(\"You are learning the ES6 tutorial\"<\/span>);<\/pre>\n

<\/code>\n <\/div>\n

\n \u5728 JavaScript \u4e2d\u6267\u884c\u4ee3\u7801\n <\/div>\n
\n \u8ba9\u6211\u4eec\u901a\u8fc7\u4e00\u4e2a\u4f8b\u5b50\u6765\u5c1d\u8bd5\u7406\u89e3\u4ee3\u7801\u5728 JavaScript \u4e2d\u662f\u5982\u4f55\u6267\u884c\u7684:\n <\/div>\n
\n
var <\/span>msg =  \"Hello World\"<\/span>       \/\/this<\/span> line declares a variable.<\/span>\nconsole.log<\/span>(msg);       \/\/this<\/span> line print <\/span>the value of the variable to the prompt. The console in it refers to the terminal window, and the log<\/span>() is used to display the text on the screen.<\/span><\/pre>\n

<\/code>\n <\/div>\n

\n \u4f7f\u7528 .js \u6269\u5c55\u540d\u4fdd\u5b58\u6b64\u6587\u4ef6\uff0c\u56e0\u4e3a\u6211\u4eec\u4f7f\u7528\u540d\u79f0 Example.js \u4fdd\u5b58\u5b83\u3002 \u7136\u540e\uff0c\u53f3\u952e\u5355\u51fb\u6b64\u6587\u4ef6\uff0c\u8be5\u6587\u4ef6\u4f4d\u4e8e\u5728 Visual Studio \u4ee3\u7801\u7684\u9879\u76ee\u8d44\u6e90\u7ba1\u7406\u5668\u7a97\u53e3\u4e2d\u9009\u62e9\u5de5\u4f5c\u6587\u4ef6\u9009\u9879\uff0c\u7136\u540e\u9009\u62e9'\u5728\u7ec8\u7aef\u4e2d\u6253\u5f00' \u9009\u9879\u3002\n <\/div>\n
\n \u5728\u7ec8\u7aef\u4e2d\u952e\u5165\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u6267\u884c\u6587\u4ef6:\n <\/div>\n
\n
node Example.js<\/pre>\n

<\/code>\n <\/div>\n

\n \u6267\u884c\u6210\u529f\u540e\uff0c\u4f1a\u5f97\u5230\u5982\u4e0b\u8f93\u51fa:\n <\/div>\n
\n
Hello World<\/pre>\n

<\/code>\n <\/div>\n

\u4e25\u683c\u6a21\u5f0f<\/h2>\n
\n \u4e25\u683c\u6a21\u5f0f\u662f\u5728 ECMAScript 5(ECMAScript \u89c4\u8303\u7684\u7b2c\u4e94\u7248)\u4e2d\u5f15\u5165\u7684\u3002\u60a8\u53ef\u4ee5\u5728\u6240\u6709\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u8fd9\u79cd\u4e25\u683c\u6a21\u5f0f\u3002\u5b83\u5c06\u5e2e\u52a9\u60a8\u7f16\u5199\u5e72\u51c0\u7684\u4ee3\u7801\uff0c\u4f8b\u5982\u9632\u6b62\u60a8\u4f7f\u7528\u672a\u58f0\u660e\u7684\u53d8\u91cf\u3002\n <\/div>\n

\u4f7f\u7528\u4e25\u683c\u6a21\u5f0f\u7684\u4f18\u70b9: <\/h3>\n
\n \u4e25\u683c\u6a21\u5f0f\u5bf9\u666e\u901a JavaScript \u8bed\u4e49\u6709\u51e0\u4e2a\u6539\u53d8:\n <\/div>\n

\u4e25\u683c\u6a21\u5f0f\u7981\u6b62\u67d0\u4e9b\u8bed\u6cd5\uff0c\u8fd9\u4e9b\u8bed\u6cd5\u53ef\u80fd\u4f1a\u5728 ECMAScript \u7684\u672a\u6765\u7248\u672c\u4e2d\u5b9a\u4e49\u3002<\/span>
\n \u4e25\u683c\u6a21\u5f0f\u901a\u8fc7\u5c06\u4e00\u4e9b JavaScript \u9759\u9ed8\u9519\u8bef\u66f4\u6539\u4e3a\u629b\u51fa\u9519\u8bef\u6765\u6d88\u9664\u5b83\u4eec\u3002<\/span>
\n \u4e25\u683c\u6a21\u5f0f\u8fd8\u4fee\u590d\u4e86\u9519\u8bef\uff0c\u8fd9\u4f7f\u5f97 JavaScript \u5f15\u64ce\u96be\u4ee5\u6267\u884c\u4f18\u5316\uff0c\u56e0\u6b64\u4e0e\u76f8\u540c\u6a21\u5f0f\u76f8\u6bd4\uff0c\u4e25\u683c\u6a21\u5f0f\u6709\u65f6\u4f1a\u8fd0\u884c\u5f97\u66f4\u5feb\u3002<\/span> <\/p>\n

\u5982\u4f55\u58f0\u660e\u4e25\u683c\u6a21\u5f0f<\/h3>\n
\n \u53ef\u4ee5\u901a\u8fc7\u5728\u5f00\u5934\u6dfb\u52a0\"use strict\";\u6765\u58f0\u660e\u4e25\u683c\u6a21\u5f0f\n <\/div>\n
\n \u5728\u811a\u672c\u5f00\u5934\u58f0\u660e: \u5f53\u4f60\u5728\u811a\u672c\u5f00\u5934\u58f0\u660e\u5b83\u65f6\uff0c\u5b83\u5c06\u662f\u4e00\u4e2a\u5168\u5c40\u8303\u56f4\uff0c\u5373\u6240\u6709\u4ee3\u7801\u811a\u672c\u5185\u5c06\u5728\u4e25\u683c\u6a21\u5f0f\u4e0b\u6267\u884c\u3002\n <\/div>\n
\n \u4f8b\u5982:\n <\/div>\n
\n
\"use strict\"<\/span>;\nexample();\nfunction example() {\n  x= 89;   \/\/ It will also cause an error because x is not declared<br><\/span>\n}<\/pre>\n

<\/code>\n <\/div>\n

\n \u5f53\u6211\u4eec\u6267\u884c\u8fd9\u4e2a\u4f8b\u5b50\u65f6\uff0c\u6211\u4eec\u4f1a\u5f97\u5230\u4e00\u4e2a\u9519\u8bef\uff0c\u56e0\u4e3a\u6211\u4eec\u6ca1\u6709\u58f0\u660e\u53d8\u91cf x\u3002\n <\/div>\n
\n \u5728\u51fd\u6570\u5185\u90e8\u58f0\u660e: \u5f53\u4f60\u5728\u51fd\u6570\u5185\u90e8\u58f0\u660e\u5b83\u65f6\uff0c\u5b83\u5c31\u662f\u4e00\u4e2a\u5c40\u90e8\u4f5c\u7528\u57df\uff0c\u5373\u51fd\u6570\u5185\u90e8\u7684\u4ee3\u7801\u5c06\u5904\u4e8e\u4e25\u683c\u6a21\u5f0f\u3002\n <\/div>\n
\n
y = 89;       \/\/ It will not cause an error.<\/span>\nexample();\nfunction example() {\n  \"use strict\"<\/span>;\n  x = 89;   \/\/ It will cause an error<\/span>\n}<\/pre>\n

<\/code>\n <\/div>\n

ES6 \u548c\u63d0\u5347<\/h2>\n
\n \u63d0\u5347 \u662f\u5728\u4ee3\u7801\u6267\u884c\u4e4b\u524d\u79fb\u52a8\u4f5c\u7528\u57df\u9876\u90e8\u7684\u6240\u6709\u58f0\u660e\u7684\u9ed8\u8ba4\u884c\u4e3a\u3002\u5b83\u9002\u7528\u4e8e\u51fd\u6570\u548c\u53d8\u91cf\u3002\u5b83\u5141\u8bb8 JavaScript \u5728\u58f0\u660e\u4e4b\u524d\u4f7f\u7528\u7ec4\u4ef6\u3002\u63d0\u5347\u4e0d\u9002\u7528\u4e8e\u5728\u4e25\u683c\u6a21\u5f0f\u4e0b\u8fd0\u884c\u7684\u811a\u672c\u3002\n <\/div>\n

<\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"ES6 \u8bed\u6cd5zh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[161],"tags":[],"class_list":["post-1905","post","type-post","status-publish","format-standard","hentry","category-es6jc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1905"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=1905"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1905\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=1905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=1905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=1905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}