-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathclass.js
More file actions
42 lines (31 loc) · 693 Bytes
/
class.js
File metadata and controls
42 lines (31 loc) · 693 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
class Person {
constructor(name) {
this.name = name;
this.movement = "walks";
}
move(meters) {
console.log(`${this.name} ${this.movement} ${meters}m.`);
}
}
class Hero extends Person {
constructor(name, movement) {
this.name = name;
this.movement = movement;
}
move() {
super.move(500);
}
}
let clark = new Person("Clark Kent");
let superman = new Hero("Superman", "flies");
clark.move(100);
// -> Clark Kent walks 100m.
superman.move();
// -> Superman flies 500m.
/* Make a note of:
class Base {}
class Derived extends Base {}
//Here, Derived.prototype will inherit from Base.prototype.
let parent = {};
class Derived prototype parent {}
*/