{"id":72,"date":"2021-01-17T19:50:18","date_gmt":"2021-01-17T11:50:18","guid":{"rendered":"http:\/\/gjweb.top\/?p=72"},"modified":"2021-01-17T19:50:19","modified_gmt":"2021-01-17T11:50:19","slug":"ecmascript-6","status":"publish","type":"post","link":"https:\/\/gjweb.top\/?p=72","title":{"rendered":"ECMAScript 6"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u5757\u7ea7\u4f5c\u7528\u57df<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>let : \u58f0\u660e\u4e00\u4e2a\u4e0d\u4f1a\u88ab\u63d0\u524d\u7684\u53d8\u91cf<\/li><li>\u4e3a\u4ec0\u4e48<\/li><li>\u4f20\u7edfjs\u4e2d\u58f0\u660e\u63d0\u524d\u7834\u574f\u4e86\u7a0b\u5e8f\u6b63\u5e38\u7684\u6267\u884c\u987a\u5e8f<\/li><li>\u4f55\u65f6:<\/li><li>\u6240\u6709\u7684var,\u90fd\u8981\u7528let\u4ee3\u66ff<\/li><li>\u5982\u4f55: \u4ee3\u66ff var<\/li><li>\u539f\u7406:<\/li><li>let \u4e4b\u524d\u5141\u8bb8\u63d0\u524d\u4f7f\u7528,\u4e5f\u4e0d\u5141\u8bb8\u91cd\u590d\u58f0\u660e<\/li><li>let\u4e3ajs\u6dfb\u52a0\u4e86\u5757\u7ea7\u4f5c\u7528\u57df<\/li><li>\u4ec0\u4e48\u662f\u5757\u7ea7\u4f5c\u7528\u57df<\/li><li>\u4ee3\u7801\u4e2d\u4efb\u4f55\u4e00\u5bf9{}\u4e4b\u95f4\u7684\u8bed\u53e5\u79f0\u4e3a\u4e00\u4e2a\u4ee3\u7801\u5757,\u4ee3\u7801\u5757\u4e2d\u7684\u53d8\u91cf,\u53ea\u80fd\u5728\u5757\u5185\u4f7f\u7528<\/li><li>\u4f55\u65f6<ul><li>\u5e0c\u671b\u4ee3\u7801\u5757\u5185\u90e8\u7684\u53d8\u91cf\u4e0d\u80fd\u5f71\u54cd\u5916\u90e8\u7684\u53d8\u91cf\u65f6<\/li><\/ul><\/li><li>\u539f\u7406:<ul><li>\u81ea\u52a8\u4f7f\u7528\u533f\u540d\u51fd\u6570\u81ea\u8c03\u65b9\u5f0f,\u5305\u62ec\u5757\u5185\u7684\u4ee3\u7801<\/li><\/ul><\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u7bad\u5934\u51fd\u6570: \u7b80\u5316\u56de\u8c03\u51fd\u6570<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4f55\u65f6<\/li><li>\u4eca\u540e\u6240\u6709\u56de\u8c03\u51fd\u6570\u90fd\u53ef\u7528\u7bad\u5934\u51fd\u6570\u7b80\u5316<\/li><li>\u5982\u4f55\u7b80\u5316<\/li><li>function \u7b80\u5316\u4e3a =&gt;<\/li><li>\u66f4\u7b80\u5316: \u5982\u679c\u53ea\u6709\u4e00\u4e2a\u53c2\u6570\u53ef\u7701\u7565\u5c0f\u62ec\u53f7<\/li><li>\u66f4\u7b80\u5316: \u5982\u679c\u56de\u8c03\u51fd\u6570\u4e2d\u53ea\u6709\u4e00\u53e5\u8bdd\u53ef\u7701\u7565\u5927\u62ec\u53f7<\/li><li>\u5982\u679c\u53ea\u6709\u4e00\u53e5return\u5219\u53ef\u4ee5\u7701\u7565 return<\/li><li><strong>\u6ce8\u610f<\/strong><ul><li>\u7bad\u5934\u51fd\u6570\u5185\u5916\u5171\u6709\u4e00\u4e2athis<\/li><li>\u7279\u4f8b<\/li><li>\u5982\u679c\u5e0c\u671b\u5185\u5916this\u4e0d\u901a\u8fc7\u662f,\u5c31\u4e0d\u80fd\u7528\u7bad\u5934\u51fd\u6570<\/li><\/ul><\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u53c2\u6570\u589e\u5f3a(\u4e09\u79cd)<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u9ed8\u8ba4\u503c: ES6\u4e2d\u53ef\u4ee5\u5bf9\u53c2\u6570\u6307\u5b9a\u9ed8\u8ba4\u503c<\/li><li>\u8c03\u7528\u65f6,\u5982\u679c\u6ca1\u6709\u4f20\u5165\u53c2\u6570\u503c,\u5219\u9ed8\u8ba4\u4f7f\u7528\u63d0\u524d\u6307\u5b9a\u7684\u9ed8\u8ba4\u503c<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>Array.prototype.indexOf = function(element,fromi=0){\r\n    \/\/ fromi = fromi || 0\r\n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>\u5f3a\u8c03<\/strong><ul><li>\u6709\u9ed8\u8ba4\u503c\u7684\u53c2\u6570,\u5fc5\u987b\u653e\u5728\u5217\u8868\u7684\u6700\u540e<\/li><\/ul><\/li><li>\u5269\u4f59rest<\/li><li>\u5f53\u4f20\u5165\u51fd\u6570\u7684\u53c2\u6570\u4e2a\u6570\u4e0d\u786e\u5b9a\u662f,\u53ef\u7528<strong>\u2026<\/strong>\u63a5\u4f4f\u5269\u4f59\u7684\u4e00\u5207\u53c2\u6570<\/li><li>\u4f55\u65f6:<ul><li>\u53c2\u6570\u4e2a\u6570\u4e0d\u786e\u5b9a\u65f6<\/li><\/ul><\/li><li>\u4e3a\u4ec0\u4e48<ul><li>arguments\u7684\u4e24\u5927\u95ee\u9898<\/li><li>\u603b\u662f\u83b7\u53d6\u5168\u90e8\u53c2\u6570,\u4e0d\u80fd\u6709\u539f\u5219\u7684\u83b7\u53d6\u90e8\u5206<\/li><li>\u662f\u7c7b\u6570\u7ec4\u5bf9\u8c61,\u4e0d\u662f\u7eaf\u6b63\u7684\u6570\u7ec4,\u4e0d\u80fd\u4f7f\u7528\u6570\u7ec4\u7684API<\/li><li>\u4e0d\u80fd\u6539\u540d<\/li><li>\u5982\u4f55<ul><li>\u5728\u51fd\u6570\u5b9a\u4e49\u662f\u53c2\u6570\u5217\u8868\u4e2d: (\u5176\u4ed6\u56fa\u5b9a\u53c2\u6570,\u2026\u6570\u7ec4\u540d)<\/li><\/ul><\/li><li>\u4f18\u70b9<ul><li>\u53ef\u6709\u539f\u5219\u7684\u83b7\u53d6\u90e8\u5206\u53c2\u6570<\/li><li>\u662f\u7eaf\u6b63\u7684\u6570\u7ec4<\/li><li>\u53ef\u81ea\u5b9a\u4e49\u540d\u79f0<\/li><\/ul><\/li><li>\u603b\u7ed3<ul><li>\u7528 rest \u66ff\u4ee3 arguments<\/li><\/ul><\/li><\/ul><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>Function.prototype.bind = function (obj,...args){\r\n    console.log(\"\u8c03\u7528\u81ea\u5b9a\u4e49\u7684bind\")\r\n    var fun = this;\r\n    return function (...sals){\r\n        fun.apply(obj,arg.concat(sals));\r\n    }\r\n}\r\nfunction calc(base,bonus1,bonus2){\r\n    console.log(this.ename + \"aaa\" + (bouns1+bonus2))\r\n}\r\nvar lilei = {ename:\"lilei\"}\r\nvar lilei_calc = calc.bind(lilei,10000)\r\nlilei_calc(2000,3000)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u6563\u64adspread:<ul><li>\u5728\u51fd\u6570\u8c03\u7528\u65f6,\u7528 <strong>&#8220;\u2026&#8221;<\/strong>\u6253\u6563\u6570\u7ec4\u7c7b\u578b\u7684\u53c2\u6570\u4e3a\u5355\u4e2a\u5143\u7d20,\u5728\u4f20\u5165\u51fd\u6570&#8212;\u4ee3\u66ffapply<\/li><li>\u4f55\u65f6<\/li><li>\u5982\u679c\u51fd\u6570\u672c\u8eab\u9700\u8981\u591a\u4e2a\u53c2\u6570\u5355\u72ec\u4f20\u5165,\u800c\u9700\u8981\u4f20\u5165\u7684\u7684\u786e\u662f\u6570\u7ec4\u65f6<\/li><li>\u5982\u4f55<\/li><li>\u5728\u8c03\u7528\u65f6,\u4f20\u5165\u53c2\u6570\u65f6\u7528<strong>&#8220;\u2026\u6570\u7ec4&#8221;<\/strong>\u6253\u6563\u6570\u7ec4\u53c2\u6570,\u5355\u4e2a\u5143\u7d20\u5206\u522b\u4f20\u5165<\/li><\/ul><\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u6784<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5b9a\u4e49<\/li><li>\u8bb2\u4e00\u4e2a\u5bf9\u8c61\u6216\u6570\u7ec4\u4e2d\u7684\u6210\u5458,\u5206\u522b\u8d4b\u503c\u7ed9\u591a\u4e2a\u5355\u72ec\u7684\u53d8\u91cf\u4e00\u4e00\u7b80\u5316\u6279\u91cf\u8d4b\u503c<\/li><li>\u4f55\u65f6<\/li><li>\u5c06\u4e00\u4e2a\u5bf9\u8c61\u548c\u6570\u7ec4\u4e2d\u7684\u6210\u5458,\u5206\u522b\u8d4b\u503c\u7ed9\u591a\u4e2a\u5355\u72ec\u53d8\u91cf\u65f6<\/li><li>\u5982\u4f55 (<strong>\u4e24\u79cd<\/strong>)<\/li><li>\u6570\u7ec4\u89e3\u6784: (\u6570\u7ec4\u89e3\u6784\u9760\u4e0b\u6807\u89e3\u6784)<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>var arr = &#91;1,2,3]\r\nvar &#91;a,b,c] = arr;\r\nconsole.log(a,b,c) \/\/ 1,2,3\r\n\/*\r\n\t\u7b14\u8bd5\u9898: \u4e0d\u7528\u7b2c\u4e09\u4e2a\u53d8\u91cf\u4ea4\u6362\u53d8\u91cf\u503c\r\n\t\tvar a =1,b=2;\r\n\t\tvar &#91;b,a] = &#91;a,b]\r\n\t\tconsole.log(a,b) \/\/ 2,1\r\n*\/<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5bf9\u8c61\u89e3\u6784 (\u5bf9\u8c61\u7ed3\u6784\u9760\u5c5e\u6027\u540d(\u5065\u540d)\u5bf9\u5e94)<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>var obj  = {y:2017,m:06,d:28};\r\nvar {y:yeay,m:metd,d:date} = obj;\r\nconsole.log(year,metd,date) \/\/ 2017,06,28<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u51fd\u6570\u8c03\u7528\u65f6\u89e3\u6784<ul><li>\u5b9a\u4e49\u51fd\u6570\u65f6<\/li><\/ul><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>function fun ({y:y,m:m,d:d}){\u6267\u884c\u8bed\u53e5}\r\nvardata= {y:2017,m:06,b:28}\r\nfun(date)<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">for of \u7b80\u5316\u7248\u7684for\u5faa\u73af<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5982\u4f55<\/li><li><code>for(var elem of arr){}<\/code><\/li><li>elem\u53ef\u76f4\u63a5\u83b7\u5f97arr\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\u503c<\/li><li>\u4f55\u65f6\uff1a \u4ee3\u66fffor\u5faa\u73af\uff0c\u904d\u5386\u4e0b\u6807\u4e3a\u6570\u5b57\u7684\u6570\u7ec4\u6216\u7c7b\u6570\u7ec4\u5bf9\u8c61<\/li><li>\u5f3a\u8c03: \u4e0d\u80fd\u904d\u5386\u5173\u8054\u6570\u636e\u548c\u5bf9\u8c61,\u56e0\u4e3a\u4e0b\u6807\u4e0d\u662f\u6570\u5b57<\/li><li>\u7f3a\u70b9<\/li><li>\u65e0\u6cd5\u83b7\u5f97\u4e0b\u6807<\/li><li>\u53ea\u80fd\u904d\u5386\u6240\u6709,\u4e0d\u80fd\u6709\u9009\u62e9\u7684\u904d\u5386<\/li><li>\u667a\u80fd\u4ece\u524d\u5411\u540e\u904d\u5386<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">class\u7c7b\u578b<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5b9a\u4e49<\/li><li>\u5c01\u88c5\u4e00\u7c7b\u5bf9\u8c61\u7edf\u4e00\u7ed3\u6784\u7684API\u7684\u7a0b\u5e8f\u7ed3\u6784\u4e00\u4e00\u7b80\u5316js\u4e2d\u7684\u9762\u5411\u5bf9\u8c61<\/li><li>\u4e3a\u5565<\/li><li>\u4f20\u7edf\u7684js\u7c7b\u578b\u5b9a\u4e49\u65b9\u5f0f\u4e0d\u7b26\u5408\u5c01\u88c5\u7684\u7279\u70b9<\/li><li>\u5982\u4f55<\/li><li>\u7b80\u5316\u7c7b\u578b\u5b9a\u4e49\u4e00\u4e00\u5c01\u88c5<ul><li>\u7528class\u7c7b\u578b\u540d{} \u5305\u62ec\u4e4b\u524d\u7684\u6784\u9020\u51fd\u6570\u548c\u539f\u578b\u5bf9\u8c61<\/li><li>\u6784\u9020\u51fd\u6570\u540d\u5347\u7ea7\u4e3acalss\u540d,\u6784\u9020\u51fd\u6570\u66f4\u540d\u4e3aconstructor<\/li><li>\u539f\u578b\u5bf9\u8c61\u65b9\u6cd5\u4e0d\u7528\u5199\u7c7b\u578b.protitype\u548cfunction\u76f4\u63a5\u5199\u5728class\u4e2d\u7684\u51fd\u6570,\u81ea\u52a8\u6dfb\u52a0\u5230prototype\u4e2d<\/li><\/ul><\/li><li>\u7b80\u5316\u7ee7\u627f<ul><li>class \u5b50\u7c7b\u578b extends \u7236\u7c7b\u578b<\/li><li>\u7c7b\u4f3c\u4e8e<\/li><\/ul><\/li><\/ul>\n\n\n\n<p>Object.setPrototype(\u5b50\u7c7b\u578b.prototype,\u7236\u7c7b\u578b.prototype)<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u501f\u7528\u7236\u7c7b\u578b\u6784\u9020\u51fd\u6570 super(\u53c2\u6570\u2026)<ul><li>\u4e0d\u7528call,\u4e0d\u7528this<\/li><li>\u5176\u4e2d: super\u7279\u8d28\u7236\u7c7b\u578b\u6784\u9020\u51fd\u6570,\u4e14\u81ea\u52a8\u5f53\u524d\u6b63\u786e\u7684this\u66ff\u4ee3\u7236\u7c7b\u6784\u9020\u51fd\u6570\u4e2dthis<\/li><li>super.\u7236\u7c7b\u578b\u539f\u578b\u65b9\u6cd5()<\/li><li>\u9759\u6001\u65b9\u6cd5<\/li><li>\u5b9a\u4e49: \u4e0d\u9700\u8981\u5b9e\u4f8b\u5316\u5bf9\u8c61,\u5c31\u53ef\u76f4\u63a5\u8bbf\u95ee\u7684\u6210\u5458<\/li><li>\u4f55\u65f6: \u53ea\u8981\u4e00\u4e2a\u65b9\u6cd5,\u4e0d\u9700\u8981\u5b9e\u4f8b\u5316\u4e5f\u80fd\u4f7f\u7528\u65f6<\/li><li>\u539f\u7406: \u76f8\u5f53\u4e8e\u76f4\u63a5\u5b9a\u4e49\u5728\u6784\u9020\u51fd\u6570\u5bf9\u8c61\u4e0a\u7684\u65b9\u6cd5<\/li><li>\u5982\u4f55:<ul><li><code>javascript static \u65b9\u6cd5(){...}<\/code><\/li><\/ul><\/li><li>\u8bbf\u95ee\u5668\u5c5e\u6027<\/li><li>get \u5c5e\u6027\u540d() {return this._\u5c5e\u6027\u540d}<\/li><li>set \u5c5e\u6027\u540d(val){}<\/li><\/ul><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5757\u7ea7\u4f5c\u7528\u57df let : \u58f0\u660e\u4e00\u4e2a\u4e0d\u4f1a\u88ab\u63d0\u524d\u7684\u53d8\u91cf \u4e3a\u4ec0\u4e48 \u4f20\u7edfjs\u4e2d\u58f0\u660e\u63d0\u524d\u7834\u574f\u4e86\u7a0b\u5e8f\u6b63\u5e38\u7684\u6267\u884c\u987a\u5e8f \u4f55\u65f6:  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-72","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/72","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=72"}],"version-history":[{"count":0,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/72\/revisions"}],"wp:attachment":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=72"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=72"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}