-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.html
2817 lines (2730 loc) · 109 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" type="image/png" href="imgs/es6.png" />
<title>ES6 examples</title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="node_modules/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css">
<!-- ES6 examples code -->
<script src="src/constants.js"></script>
<script src="src/scoping.js"></script>
<script src="src/arrow_functions.js"></script>
<script src="src/extended_parameter_handling.js"></script>
<script src="src/template_literals.js"></script>
<script src="src/extended_literals.js"></script>
<script src="src/enhanced_regular_expression.js"></script>
<script src="src/enhanced_object_properties.js"></script>
<script src="src/destructuring_assignment.js"></script>
<script src="src/modules.js"></script>
<script src="src/modules2.js"></script>
<script src="src/modules2.js"></script>
<script src="src/classes.js"></script>
<script src="src/symbol_type.js"></script>
<script src="src/iterators.js"></script>
<script src="src/generators.js"></script>
<script src="src/map_set_and_weakmap_weakset.js"></script>
<script src="src/typed_arrays.js"></script>
<script src="src/new_built_in_methods.js"></script>
<script src="src/promises.js"></script>
<script src="src/meta_programming.js"></script>
<script src="src/internationalization_and_localization.js"></script>
</head>
<body>
<button onclick="topFunction()" id="goTop" title="Go to top"><i class="fa fa-chevron-up" aria-hidden="true"></i></button>
<div class="container">
<nav class="navbar navbar-toggleable-md navbar-inverse bg-primary">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="./">
<img src="imgs/es6.png" width="30" height="30" class="d-inline-block align-top" alt=""> ECMAScript 6
</a>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item active dropdown">
<a class="nav-link dropdown-toggle" href="" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Features
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-header h6" href="#constants">Constants</a>
<a class="dropdown-item" href="#constants-01">Constants</a>
<div class="dropdown-divider"></div>
<a class="dropdown-header h6" href="#scoping">Scoping</a>
<a class="dropdown-item" href="#block-scoped-variables">Block-Scoped Variables</a>
<a class="dropdown-item" href="#block-scoped-functions">Block-Scoped Functions</a>
<div class="dropdown-divider"></div>
<a class="dropdown-header h6" href="#arrow-functions">Arrow Functions</a>
<a class="dropdown-item" href="#expression-bodies">Expression Bodies</a>
<a class="dropdown-item" href="#statement-bodies">Statement Bodies</a>
<a class="dropdown-item" href="#lexical-this">Lexical <code>this</code></a>
<div class="dropdown-divider"></div>
<a class="dropdown-header h6" href="#extended-parameter-handling">Extended Parameter Handling</a>
<a class="dropdown-item" href="#default-parameter-values">Default Parameter Values</a>
<a class="dropdown-item" href="#rest-parameter">Rest Parameter</a>
<a class="dropdown-item" href="#spread-operator">Spread Operator</a>
<div class="dropdown-divider"></div>
<a class="dropdown-header h6" href="#template-literals">Template Literals</a>
<a class="dropdown-item" href="#string-interpolation">String Interpolation</a>
<a class="dropdown-item" href="#custom-interpolation">Custom Interpolation</a>
<a class="dropdown-item" href="#raw-string-access">Raw String Access</a>
<div class="dropdown-divider"></div>
<a class="dropdown-header h6" href="#extended-literals">Extended Literals</a>
<a class="dropdown-item" href="#binary-and-octal-literal">Binary & Octal Literal</a>
<a class="dropdown-item" href="#unicode-string-and-regexp-literal">Unicode String & RegExp Literal</a>
<div class="dropdown-divider"></div>
<a class="dropdown-header h6" href="#enhanced-regular-expression">Enhanced Regular Expression</a>
<a class="dropdown-item" href="#regular-expression-sticky-matching">Regular Expression Sticky Matching</a>
<div class="dropdown-divider"></div>
<a class="dropdown-header h6" href="#enhanced-object-properties">Enhanced Object Properties</a>
<a class="dropdown-item" href="#property-shorthand">Property Shorthand</a>
<a class="dropdown-item" href="#computed-property-names">Computed Property Names</a>
<a class="dropdown-item" href="#method-properties">Method Properties</a>
<div class="dropdown-divider"></div>
<a class="dropdown-header h6" href="#destructuring-assignment">Destructuring Assignment</a>
<a class="dropdown-item" href="#array-matching">Array Matching</a>
<a class="dropdown-item" href="#object-matching-shorthand-notation">Object Matching, Shorthand Notation</a>
<a class="dropdown-item" href="#object-matching-deep-matching">Object Matching, Deep Matching</a>
<a class="dropdown-item" href="#object-and-array-matching-default-values">Object And Array Matching, Default Values</a>
<a class="dropdown-item" href="#parameter-context-matching">Parameter Context Matching</a>
<a class="dropdown-item" href="#fail-soft-destructuring">Fail-Soft Destructuring</a>
<div class="dropdown-divider"></div>
<a class="dropdown-header h6" href="#modules">Modules</a>
<a class="dropdown-item" href="#value-export-import">Value Export/Import</a>
<a class="dropdown-item" href="#default-and-wildcard">Default & Wildcard</a>
<div class="dropdown-divider"></div>
<a class="dropdown-header h6" href="#classes">Classes</a>
<a class="dropdown-item" href="#class-definition">Class Definition</a>
<a class="dropdown-item" href="#class-inheritance">Class Inheritance</a>
<a class="dropdown-item" href="#class-inheritance-from-expressions">Class Inheritance, From Expressions</a>
<a class="dropdown-item" href="#base-class-access">Base Class Access</a>
<a class="dropdown-item" href="#static-members">Static Members</a>
<a class="dropdown-item" href="#getter-setter">Getter/Setter</a>
<div class="dropdown-divider"></div>
<a class="dropdown-header h6" href="#symbol-type">Symbol Type</a>
<a class="dropdown-item" href="#symbol-type-01">Symbol Type</a>
<a class="dropdown-item" href="#global-symbols">Global Symbols</a>
<div class="dropdown-divider"></div>
<a class="dropdown-header h6" href="#iterators">Iterators</a>
<a class="dropdown-item" href="#iterator-and-for-of-operator">Iterator & For-Of Operator</a>
<div class="dropdown-divider"></div>
<a class="dropdown-header h6" href="#generators">Generators</a>
<a class="dropdown-item" href="#generator-function-iterator-protocol">Generator Function, Iterator Protocol</a>
<a class="dropdown-item" href="#generator-function-direct-use">Generator Function, Direct Use</a>
<a class="dropdown-item" href="#generator-matching">Generator Matching</a>
<a class="dropdown-item" href="#generator-control-flow">Generator Control-Flow</a>
<a class="dropdown-item" href="#generator-methods">Generator Methods</a>
<div class="dropdown-divider"></div>
<a class="dropdown-header h6" href="#map-set-and-weakmap-weakset">Map/Set & WeakMap/WeakSet</a>
<a class="dropdown-item" href="#set-data-structure">Set Data-Structure</a>
<a class="dropdown-item" href="#map-data-structure">Map Data-Structure</a>
<a class="dropdown-item" href="#weak-link-data-structures">Weak-Link Data-Structures</a>
<div class="dropdown-divider"></div>
<a class="dropdown-header h6" href="#typed-arrays">Typed Arrays</a>
<a class="dropdown-item" href="#typed-arrays-01">Typed Arrays</a>
<div class="dropdown-divider"></div>
<a class="dropdown-header h6" href="#new-built-in-methods">New Built-In Methods</a>
<a class="dropdown-item" href="#object-property-assignment">Object Property Assignment</a>
<a class="dropdown-item" href="#array-element-finding">Array Element Finding</a>
<a class="dropdown-item" href="#string-repeating">String Repeating</a>
<a class="dropdown-item" href="#string-searching">String Searching</a>
<a class="dropdown-item" href="#number-type-checking">Number Type Checking</a>
<a class="dropdown-item" href="#number-safety-checking">Number Safety Checking</a>
<a class="dropdown-item" href="#number-comparison">Number Comparison</a>
<a class="dropdown-item" href="#number-truncation">Number Truncation</a>
<a class="dropdown-item" href="#number-sign-determination">Number Sign Determination</a>
<div class="dropdown-divider"></div>
<a class="dropdown-header h6" href="#promises">Promises</a>
<a class="dropdown-item" href="#promise-usage">Promise Usage</a>
<a class="dropdown-item" href="#promise-combination">Promise Combination</a>
<div class="dropdown-divider"></div>
<a class="dropdown-header h6" href="#meta-programming">Meta-Programming</a>
<a class="dropdown-item" href="#proxying">Proxying</a>
<a class="dropdown-item" href="#reflection">Reflection</a>
<div class="dropdown-divider"></div>
<a class="dropdown-header h6" href="#internationalization-and-localization">Internationalization & Localization</a>
<a class="dropdown-item" href="#collation">Collation</a>
<a class="dropdown-item" href="#number-formatting">Number Formatting</a>
<a class="dropdown-item" href="#currency-formatting">Currency Formatting</a>
<a class="dropdown-item" href="#date-time-formatting">Date/Time Formatting</a>
</div>
</li>
</ul>
</div>
</nav>
<br/>
<div class="jumbotron">
<a href="https://github.com/gatosnake/ES6-examples">
<img style="position: absolute; top: 80px; right: 15px; border: 0;" src="https://camo.githubusercontent.com/652c5b9acfaddf3a9c326fa6bde407b87f7be0f4/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png">
</a>
<h1 class="display-3 hidden-xs-down">ECMAScript 6</h1>
<h1 class="display-3 hidden-sm-up">ES6</h1>
<p class="lead">Examples of all features in ECMAScript 6</p>
<hr class="my-4">
<p>This page shows examples of all features in ECMAScript 6. They are based on examples from the site <a href="http://es6-features.org" target="_blank">http://es6-features.org</a>.</p>
<p>All credits to <a href="http://es6-features.org" target="_blank">http://es6-features.org</a>.</p>
<p>The GitHub repository is available at <a href="https://github.com/gatosnake/es6-examples" target="_blank">https://github.com/gatosnake/es6-examples</a>.</p>
<p>All examples are executed in this page, just open the developer tools in your browser and look at the console ;) . If your browser does not support ES6 code, go to <a href="./6to5">this link</a> that has the same code compiled to ES5.</p>
</div>
<!-- Constants -->
<article id="constants">
<div class="row">
<div class="col">
<h2>Constants</h2>
<br/>
</div>
</div>
<section id="constants-01">
<div class="row">
<div class="col">
<h4>Constants</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>Support for constants (also known as "immutable variables"), i.e., variables which cannot be re-assigned new content. Notice: this only makes the variable itself immutable, not its assigned content (for instance, in case the content
is an object, this means the object itself can still be altered).</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">const PI = 3.141593;
console.log(PI > 3.0);</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">true</code></pre>
</div>
</div>
</section>
</article>
<br/>
<!-- Scoping -->
<article id="scoping">
<div class="row">
<div class="col">
<h2>Scoping</h2>
<br/>
</div>
</div>
<!-- block scoped variables -->
<section id="block-scoped-variables">
<div class="row">
<div class="col">
<h4>Block-Scoped Variables</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>Block-scoped variables (and constants) without hoisting.</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">let a = new Array('a', 'b', 'c');
let b = new Array('d', 'e', 'f');
let x = new Array('1', '2');
let y = new Array('3', '4');
for (let i = 0; i < a.length; i++) {
let x = a[i];
console.log(`Value x[${i}]:`, x);
}
for (let i = 0; i < b.length; i++) {
let y = b[i];
console.log(`Value y[${i}]:`, y);
}
console.log(`Array x:`, JSON.stringify(x));
console.log(`Array y:`, JSON.stringify(y));
let callbacks = []
for (let i = 0; i <= 2; i++) {
callbacks[i] = function() {
return i * 2;
}
}
console.log(`Compare callback[0] === 0:`, callbacks[0]() === 0);
console.log(`Compare callback[1] === 2:`, callbacks[1]() === 2);
console.log(`Compare callback[2] === 4:`, callbacks[2]() === 4);</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Value x[0]: a
Value x[1]: b
Value x[2]: c
Value y[0]: d
Value y[1]: e
Value y[2]: f
Array x: ["1","2"]
Array y: ["3","4"]
Compare callback[0] === 0: true
Compare callback[1] === 2: true
Compare callback[2] === 4: true</code></pre>
</div>
</div>
</section>
<!-- block scoped functions -->
<br/>
<section id="block-scoped-functions">
<div class="row">
<div class="col">
<h4>Block-Scoped Functions</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>Block-scoped function definitions.</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">function foo() {
return 1;
}
console.log(`Compare foo() === 1:`, foo() === 1);
{
function foo() {
return 2;
}
console.log(`Compare foo() === 2:`, foo() === 2);
}
console.log(`Compare foo() === 1:`, foo() === 1);</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Compare foo() === 1: true
Compare foo() === 2: true
Compare foo() === 1: true</code></pre>
</div>
</div>
</section>
</article>
<br/>
<!-- Arrow Functions -->
<article id="arrow-functions">
<div class="row">
<div class="col">
<h2>Arrow Functions</h2>
<br/>
</div>
</div>
<!-- expression bodies-->
<section id="expression-bodies">
<div class="row">
<div class="col">
<h4>Expression Bodies</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>More expressive closure syntax.</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">let evens = new Array(1, 2, 3);
let odds = evens.map(v => v + 1);
let pairs = evens.map(v => ({
even: v,
odd: v + 1
}));
let nums = evens.map((v, i) => v + i);
console.log(`Array odds:`, JSON.stringify(odds));
console.log(`Array pairs:`, JSON.stringify(pairs));
console.log(`Array nums:`, JSON.stringify(nums));</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Array odds: [2,3,4]
Array pairs: [{"even":1,"odd":2},{"even":2,"odd":3},{"even":3,"odd":4}]
Array nums: [1,3,5]</code></pre>
</div>
</div>
</section>
<!-- statement bodies-->
<br/>
<section id="statement-bodies">
<div class="row">
<div class="col">
<h4>Statement Bodies</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>More expressive closure syntax.</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">let nums = new Array(2, 5, 3, 6, 8, 4, 5, 1, 5);
let fives = new Array();
nums.forEach(v => {
if (v % 5 === 0)
fives.push(v);
});
console.log(`Array fives:`, JSON.stringify(fives));</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Array fives: [5,5,5]</code></pre>
</div>
</div>
</section>
<br/>
<!-- lexical this-->
<section id="lexical-this">
<div class="row">
<div class="col">
<h4>Lexical <code>This</code></h4>
</div>
</div>
<div class="row">
<div class="col">
<p>More intuitive handling of current object context.</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">let example = {
nums: [2, 5, 3, 6, 8, 4, 5, 1, 5],
fives: [],
getFives: function() {
this.nums.forEach((v) => {
if (v % 5 === 0)
this.fives.push(v);
});
}
}
example.getFives();
console.log(`Array example.nums:`, JSON.stringify(example.fives));</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Array example.nums: [5,5,5]</code></pre>
</div>
</div>
</section>
</article>
<br/>
<!-- extended parameter handling -->
<article id="extended-parameter-handling">
<div class="row">
<div class="col">
<h2>Extended Parameter Handling</h2>
<br/>
</div>
</div>
<!-- Default Parameter Values-->
<section id="default-parameter-values">
<div class="row">
<div class="col">
<h4>Default Parameter Values</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>Simple and intuitive default values for function parameters.</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">function function1(x, y = 7, z = 42) {
return x + y + z;
}
console.log(`Compare function1() === 50:`, function1(1) === 50);</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Compare function1() === 50: true</code></pre>
</div>
</div>
</section>
<br/>
<!-- Rest Parameter-->
<section id="rest-parameter">
<div class="row">
<div class="col">
<h4>Rest Parameter</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>Aggregation of remaining arguments into single parameter of variadic functions.</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">let a = new Array(1, 2, 3, 4, 5);
function function2(x, y, ...a) {
return (x + y) * a.length;
}
console.log(`Compare function2() === 9:`, function2(1, 2, "hello", true, 7) === 9);</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Compare function2() === 9: true</code></pre>
</div>
</div>
</section>
<br/>
<!-- Spread Operator-->
<section id="spread-operator">
<div class="row">
<div class="col">
<h4>Spread Operator</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>Spreading of elements of an iterable collection (like an array or even a string) into both literal elements and individual function parameters.</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">function function2(x, y, ...a) {
return (x + y) * a.length;
}
let params = ["hello", true, 7];
console.log(`Compare function2() === 9:`, function2(1, 2, ...params) === 9);
let other = [1, 2, ...params];
console.log(`Array other:`, JSON.stringify(other));
let str = "foo";
let chars = [...str];
console.log(`Array chars:`, JSON.stringify(chars));</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Compare function2() === 9: true
Array other: [1,2,"hello",true,7]
Array chars: ["f","o","o"]</code></pre>
</div>
</div>
</section>
</article>
<br/>
<!-- Template Literals -->
<article id="template-literals">
<div class="row">
<div class="col">
<h2>Template Literals</h2>
<br/>
</div>
</div>
<!-- String Interpolation-->
<section id="string-interpolation">
<div class="row">
<div class="col">
<h4>String Interpolation</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>Intuitive expression interpolation for single-line and multi-line strings. (Notice: don't be confused, Template Literals were originally named "Template Strings" in the drafts of the ECMAScript 6 language specification)</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">let customer = {
name: "Foo"
};
let card = {
amount: 7,
product: "Bar",
unitprice: 42
};
let message = `Hello ${customer.name},
want to buy ${card.amount} ${card.product} for
a total of ${card.amount * card.unitprice} bucks?`;
console.log(`Value message:`, message);</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Value message: Hello Foo,
want to buy 7 Bar for
a total of 294 bucks?</code></pre>
</div>
</div>
</section>
<br/>
<!-- Custom Interpolation-->
<section id="custom-interpolation">
<div class="row">
<div class="col">
<h4>Custom Interpolation</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>Flexible expression interpolation for arbitrary methods.</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">function get(array, param1, param2) {
console.log(`Value params get():`, JSON.stringify(array), param1, param2);
let url = `${array[0]}${param1}${array[1]}${param2}`;
console.log(`Value url:`, url);
}
let bar = `Hola`;
let baz = `Mundo`;
let asd = `Cristhian`;
get `http://example.com/foo?bar=${bar + baz}&quux=${asd}`;</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Value params get(): ["http://example.com/foo?bar=","&quux=",""] HolaMundo Cristhian
Value url: http://example.com/foo?bar=HolaMundo&quux=Cristhian</code></pre>
</div>
</div>
</section>
<br/>
<!-- Raw String Access-->
<section id="raw-string-access">
<div class="row">
<div class="col">
<h4>Raw String Access</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>Access the raw template string content (backslashes are not interpreted).</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">function quux(strings, ...values) {
console.log(`Compare strings[0] === "foo\\n":`, strings[0] === "foo\n");
console.log(`Compare strings[1] === "bar":`, strings[1] === "bar");
console.log(`Compare values[0] === 42:`, values[0] === 42);
console.log(`Compare strings.raw[0] === "foo\\\\n":`, strings.raw[0] === "foo\\n");
console.log(`Compare strings.raw[1] === "bar":`, strings.raw[1] === "bar");
}
quux `foo\n${ 42 }bar`;
console.log(`Compare String.war:`, String.raw `foo\n${ 42 }bar` === "foo\\n42bar");</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Compare strings[0] === "foo\n": true
Compare strings[1] === "bar": true
Compare values[0] === 42: true
Compare strings.raw[0] === "foo\\n": true
Compare strings.raw[1] === "bar": true
Compare String.war: true</code></pre>
</div>
</div>
</section>
</article>
<br/>
<!-- Extended Literals -->
<article id="extended-literals">
<div class="row">
<div class="col">
<h2>Extended Literals</h2>
<br/>
</div>
</div>
<!-- Binary & Octal Literal-->
<section id="binary-and-octal-literal">
<div class="row">
<div class="col">
<h4>Binary & Octal Literal</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>Direct support for safe binary and octal literals.</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">console.log(`Compare binary 0b111110111 === 503:`, 0b111110111 === 503);
console.log(`Compare octal 0o767 === 503:`, 0o767 === 503);</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Compare binary 0b111110111 === 503: true
Compare octal 0o767 === 503: true</code></pre>
</div>
</div>
</section>
<br/>
<!-- Unicode String & RegExp Literal-->
<section id="unicode-string-and-regexp-literal">
<div class="row">
<div class="col">
<h4>Unicode String & RegExp Literal</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>Extended support using Unicode within strings and regular expressions.</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">console.log(`Compare "𠮷".length === 2:`, "𠮷".length === 2);
console.log(`Compare "𠮷".match(/./u)[0].length === 2:`, "𠮷".match(/./u)[0].length === 2);
console.log(`Compare "𠮷" === "\\uD842\\uDFB7":`, "𠮷" === "\uD842\uDFB7");
console.log(`Compare "𠮷" === "\\u{20BB7}":`, "𠮷" === "\u{20BB7}");
console.log(`Compare "𠮷".codePointAt(0) == 0x20BB7:`, "𠮷".codePointAt(0) == 0x20BB7);
for (let codepoint of "𠮷") console.log(`Value codepoint:`, codepoint);</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Compare "𠮷".length === 2: true
Compare "𠮷".match(/./u)[0].length === 2: true
Compare "𠮷" === "\uD842\uDFB7": true
Compare "𠮷" === "\u{20BB7}": true
Compare "𠮷".codePointAt(0) == 0x20BB7: true
Value codepoint: 𠮷</code></pre>
</div>
</div>
</section>
</article>
<br/>
<!-- Enhanced Regular Expression -->
<article id="enhanced-regular-expression">
<div class="row">
<div class="col">
<h2>Enhanced Regular Expression</h2>
<br/>
</div>
</div>
<!-- Regular Expression Sticky Matching-->
<section id="regular-expression-sticky-matching">
<div class="row">
<div class="col">
<h4>Regular Expression Sticky Matching</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>Keep the matching position sticky between matches and this way support efficient parsing of arbitrary long input strings, even with an arbitrary number of distinct regular expressions.</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">let message = "My name is Foo and my lastname is Bar."
let pattern = /my [a-zA-Z]+/y;
console.log(`Return pattern /my [a-zA-Z]+/y:`, JSON.stringify(pattern.exec(message)));
pattern.lastIndex = 19;
console.log(`Return pattern /my [a-zA-Z]+/y:`, JSON.stringify(pattern.exec(message)));
console.log(`Return pattern /my [a-zA-Z]+/y:`, JSON.stringify(pattern.exec(message)));</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Return pattern /my [a-zA-Z]+/y: null
Return pattern /my [a-zA-Z]+/y: ["my lastname"]
Return pattern /my [a-zA-Z]+/y: null</code></pre>
</div>
</div>
</section>
</article>
<br/>
<!-- Enhanced Object Properties -->
<article id="enhanced-object-properties">
<div class="row">
<div class="col">
<h2>Enhanced Object Properties</h2>
<br/>
</div>
</div>
<!-- Property Shorthand-->
<section id="property-shorthand">
<div class="row">
<div class="col">
<h4>Property Shorthand</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>Shorter syntax for common object property definition idiom.</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">let x = 1;
let y = 2;
let obj = {
x,
y
};
console.log(`Value obj:`, JSON.stringify(obj));</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Value obj: {"x":1,"y":2}</code></pre>
</div>
</div>
</section>
<br/>
<!-- Computed Property Names-->
<section id="computed-property-names">
<div class="row">
<div class="col">
<h4>Computed Property Names</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>Support for computed names in object property definitions.</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">let quux = () => ` foo`;
let obj2 = {
foo: "bar",
["baz" + quux()]: 42
};
console.log(`Value obj2:`, JSON.stringify(obj2));</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Value obj2: {"foo":"bar","baz foo":42}</code></pre>
</div>
</div>
</section>
<br/>
<!-- Method Properties-->
<section id="method-properties">
<div class="row">
<div class="col">
<h4>Method Properties</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>Support for method notation in object property definitions, for both regular functions and generator functions.</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">let obj3 = {
foo(a, b) {
a + b;
},
bar(x, y) {
x * y;
},
* quux2(x, y) {
x + y;
}
};
console.log(`Value obj3:`, obj3);</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Value obj3: Object {foo: function, bar: function, quux2: function}</code></pre>
</div>
</div>
</section>
</article>
<br/>
<!-- Destructuring Assignment -->
<article id="destructuring-assignment">
<div class="row">
<div class="col">
<h2>Destructuring Assignment</h2>
<br/>
</div>
</div>
<!-- Array Matching-->
<section id="array-matching">
<div class="row">
<div class="col">
<h4>Array Matching</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>Intuitive and flexible destructuring of Arrays into individual variables during assignment.</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">var list = [1, 2, 3];
var [a, , b] = list;
console.log(`Value a:`, a);
console.log(`Value b:`, b);
[b, a] = [a, b];
console.log(`Value a:`, a);
console.log(`Value b:`, b);</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Value a: 1
Value b: 3
Value a: 3
Value b: 1</code></pre>
</div>
</div>
</section>
<br/>
<!-- Object Matching, Shorthand Notation-->
<section id="object-matching-shorthand-notation">
<div class="row">
<div class="col">
<h4>Object Matching, Shorthand Notation</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>Intuitive and flexible destructuring of Objects into individual variables during assignment.</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">function getASTNode() {
return {op: 1, lhs: 2, rhs: 3};
};
var {op, lhs, rhs} = getASTNode();
console.log(`Value op:`, op);
console.log(`Value lhs:`, lhs);
console.log(`Value rhs:`, rhs);</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Value op: 1
Value lhs: 2
Value rhs: 3</code></pre>
</div>
</div>
</section>
<br/>
<!-- Object Matching, Deep Matching-->
<section id="object-matching-deep-matching">
<div class="row">
<div class="col">
<h4>Object Matching, Deep Matching</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>Intuitive and flexible destructuring of Objects into individual variables during assignment.</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">function getASTNode2() {
return {op: 1, lhs: {op: 2}, rhs: 3};
};
var {op: a, lhs: {op: b}, rhs: c} = getASTNode2();
console.log(`Value a:`, a);
console.log(`Value b:`, b);
console.log(`Value c:`, c);</code></pre>
</div>
<div class="col-12 col-md-6">
<h6>Result</h6>
<pre><code class="language-javascript">Value a: 1
Value b: 2
Value c: 3</code></pre>
</div>
</div>
</section>
<br/>
<!-- Object And Array Matching, Default Values-->
<section id="object-and-array-matching-default-values">
<div class="row">
<div class="col">
<h4>Object And Array Matching, Default Values</h4>
</div>
</div>
<div class="row">
<div class="col">
<p>Simple and intuitive default values for destructuring of Objects and Arrays.</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<h6>Code</h6>
<pre><code class="language-javascript">var obj = {a: 1};