forked from PatrickJS/angular-webpack-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.destructuring.ts
More file actions
67 lines (38 loc) · 891 Bytes
/
3.destructuring.ts
File metadata and controls
67 lines (38 loc) · 891 Bytes
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
// ES6
// import {ClassObject} from 'framework/or/library';
// ES5
// var lib = require('framework/or/library');
// var ClassObject = lib.ClassObject;
var { x, y } = { x: 11, y: 8 }; // x = 11; y = 8
console.log(x,y);
// This declaration is equivalent to:
var { x: x, y: y } = { x: 11, y: 8 };
console.log(x,y);
// swap variables in ES5
!function() {
let a = 1;
let b = 2;
console.log(a, b); // 1,2
let temp = b; // hold the value in a temp var
b = a;
a = temp
console.log(a, b); // 2,1
}();
// in ES6 we can use an array as our temp placeholder
!function() {
let a = 1;
let b = 2;
console.log(a, b); // 1,2
[b, a] = [a, b];
console.log(a, b); // 2,1
}();
// now it's look at it in ES5
!function() {
let a = 1;
let b = 2;
console.log(a, b); // 1,2
let temp = [a, b];
b = temp[0];
a = temp[1];
console.log(a, b); // 2,1
}();