-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemo08_class.js
58 lines (46 loc) · 1.04 KB
/
Demo08_class.js
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
/**
* * Define Class in ES6
*/
console.clear();
//? Define base class (Parent Class)
class Parents {
// Define attribute inside constructor
constructor(value = 'anonymous') {
this.name = value;
}
get Name() {
return this.name;
}
set Name(value) {
this.name = value;
}
toString() {
return `Name of object is ${this.name}`;
}
static getType() {
return "Parents";
}
}
//? Define Child class extends from Parents class
class Child extends Parents {
constructor() {
super(); // call attribute or method of Parents
this.hight = 100;
}
toString() {
return `${this.name} is tall ${this.hight}`;
}
static getType() {
return "Child";
}
}
let parents = new Parents();
parents.name = "Mary";
parents.Name = "Petter";
console.log(parents);
console.log(parents.toString());
console.log(Parents.getType());
let child = new Child();
console.log(child);
console.log(child.toString());
console.log(Child.getType());