-
Notifications
You must be signed in to change notification settings - Fork 7
/
syntax-es6.ts
119 lines (88 loc) · 1.76 KB
/
syntax-es6.ts
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
// * ------------------------------------------------ for of
{
const arr = [1, 2, 3];
for (const val of arr) {
console.log(val);
}
}
// * ---------------- for in
{
const arr = [1, 2, 3];
for (const key in arr) {
const val = arr[key];
console.log(val);
}
}
// * ------------------------------------------------ string
{
const language = 'JavaScript';
const str6 = `Hello ${language}`;
console.log(str6);
}
// * ---------------- in ES5
{
var language = 'JavaScript';
var str5 = 'Hello' + ' ' + language;
console.log(str5);
}
// * ------------------------------------------------ array function
{
const arrFn = (a) => a + 1;
console.log(arrFn(6));
}
// * ---------------- in ES5
{
function fnFn(a) {
return a + 1;
}
console.log(fnFn(6));
}
// * ------------------------------------------------ class
{
class Class6 {
val;
constructor(val) {
this.val = val;
}
log() {
console.log(this.val);
}
}
new Class6('hello').log();
}
// * ---------------- in ES5
{
function Class5(val) {
this.val = val;
}
Class5.prototype.log = function() {
console.log(this.val);
};
new Class5('hello').log();
}
// * ------------------------------------------------ destructing
{
const arr = [1, 2];
const [a, b] = arr;
const obj = { c: 3, d: 4, e: 5 };
const { c, ...d } = obj;
const arr2 = [6, 7, 8];
const [e, ...f] = arr2;
console.log(a, b, c, d, e, f);
}
// * ---------------- in ES5
{
var arr = [1, 2];
var a = arr[0];
var b = arr[1];
var obj = { c: 3, d: 4, e: 5 };
var c = obj.c;
var d = {};
for (var k in obj) {
if (k !== 'c') d[k] = obj[k];
}
var arr2 = [6, 7, 8];
var e = arr2[0];
var f = arr2.slice(1);
console.log(a, b, c, d, e, f);
}