forked from OleksiyRudenko/a-tiny-JS-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
indexClass.js
67 lines (56 loc) · 1.57 KB
/
indexClass.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
59
60
61
62
63
64
65
66
67
class Inhabitants {
constructor(species, name, gender, saying) {
this.species = species;
this.name = name;
this.gender = gender;
this.saying = saying;
}
tellAboutClass() {
return `${this.saying} My name is ${this.name} I am ${this.species} ${this.gender}.`;
}
}
class Animal extends Inhabitants{
constructor(species, name, gender, saying) {
super(species, name, gender, saying);
this.legs = 4;
}
tellAboutClass() {
return super.tellAboutClass() + `I have ${this.legs} legs`;
}
}
class Cat extends Animal {
constructor(name, gender, saying) {
super('cat', name, gender, saying);
}
}
class Dog extends Animal {
constructor(name, gender, saying) {
super('dog', name, gender, saying);
}
}
class Human extends Inhabitants{
constructor(name, gender, saying) {
super('human', name, gender, saying);
this.hands = 2;
this.legs = 2;
}
tellAboutClass() {
return super.tellAboutClass() + `I have ${this.hands} hands and ${this.legs} legs`;
}
}
class Man extends Human {
constructor(name, saying) {
super(name, 'male', saying);
}
}
class Woman extends Human {
constructor(name, saying) {
super(name, 'female', saying);
}
}
const john = new Man('John', 'Hi');
const mary = new Woman('Mary', 'Hello');
const boris = new Dog('Boris', 'male', 'Woof');
const sam = new Cat('Sam', 'female', 'Meoow');
const inhabitants = [john, mary, boris, sam];
inhabitants.forEach( item => print(item.tellAboutClass()));