Skip to content

Commit 59055a9

Browse files
committed
ES6: enhanceded object properties
1 parent 46960da commit 59055a9

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-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="11-ES6EnhancedObjectProperties.js"></script>
9+
10+
</body>
11+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
//code above is the same as
7+
var x = 'a';
8+
var y = 'b';
9+
10+
var obj2 = { x: x, y: y };
11+
console.log(obj2); // { x: "a", y: "b" }
12+
13+
14+
// Method Properties
15+
var hello = {
16+
name : 'abcdef',
17+
printHello(){
18+
console.log('Hello');
19+
}
20+
}
21+
console.log(hello.printHello());
22+
23+
//code above is the same as:
24+
var hello2 = {
25+
name: 'abcdef',
26+
printHello: function printHello() {
27+
console.log('Hello');
28+
}
29+
};
30+
console.log(hello2.printHello());

0 commit comments

Comments
 (0)