Skip to content

Commit a26b00e

Browse files
committed
ES6 obj properties example
1 parent a185e86 commit a26b00e

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head lang="en">
4+
<meta charset="UTF-8">
5+
<title></title>
6+
</head>
7+
<body>
8+
<script type="text/javascript" src="15-ES6EnhancedObjectProperties.js"></script>
9+
10+
</body>
11+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Destructuring Assignment + Property Shorthand
2+
var [x, y] = ['a', 'b'];
3+
var obj = { x, y };
4+
console.log(obj); // { x: "a", y: "b" }
5+
6+
[x, y] = [y, x];
7+
var temp = x;
8+
x = y;
9+
y = temp;
10+
11+
//code above is the same as
12+
var x = 'a';
13+
var y = 'b';
14+
var obj2 = { x: x, y: y };
15+
console.log(obj2); // { x: "a", y: "b" }
16+
17+
18+
// Method Properties
19+
var hello = {
20+
name : 'abcdef',
21+
printHello(){
22+
console.log('Hello');
23+
}
24+
}
25+
console.log(hello.printHello());
26+
27+
//code above is the same as:
28+
var hello2 = {
29+
name: 'abcdef',
30+
printHello: function printHello() {
31+
console.log('Hello');
32+
}
33+
};
34+
console.log(hello2.printHello());

0 commit comments

Comments
 (0)