forked from OleksiyRudenko/a-tiny-JS-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (60 loc) · 1.44 KB
/
index.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
68
69
class Inhabitant {
constructor(species, name, gender, saying) {
this.species = species;
this.name = name;
this.gender = gender;
this.saying = saying;
this.properties = ['species', 'name', 'gender', 'saying'];
}
toString() {
return this.properties
.map((propName) => this[propName])
.join('; ');
}
}
class Mammal extends Inhabitant {
constructor(species, name, gender, saying) {
super(species, name, gender, saying);
this.legs = 4;
this.properties = [...this.properties, 'legs'];
}
}
class Human extends Inhabitant {
constructor(name, gender, saying) {
super('human', name, gender, saying);
this.legs = 2;
this.hands = 2;
this.properties = [...this.properties, 'legs', 'hands'];
}
}
class Dog extends Mammal {
constructor(name, gender) {
super('dog', name, gender, 'woof');
}
}
class Cat extends Mammal {
constructor(name, gender) {
super('cat', name, gender, 'meow');
}
}
class Woman extends Human {
constructor(name, saying) {
super(name, 'female', saying);
}
}
class Man extends Human {
constructor(name, saying) {
super(name, 'male', saying);
}
}
const dog = new Dog('Patron', 'male');
const cat = new Cat('Murzyk', 'male');
const woman = new Woman('Anna', 'Hola');
const man = new Man('Joey', 'How you doin');
const inhabitantDetails = [
String(dog),
String(cat),
String(woman),
String(man),
];
inhabitantDetails.forEach((item) => print(item));