-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOO-override-methods.js
53 lines (42 loc) · 929 Bytes
/
OO-override-methods.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
/*
Working with override methods and attributes
*/
class Animal{
constructor(color, weight){
this.color = color;
this.weight = weight;
}
toSleep(){
document.write('Sleeping');
}
run(){
document.write('Running');
}
}
class Dog extends Animal{
constructor(color, weight, breed){
super(color, weight);
this.breed = breed;
}
getInfo(){
document.write(
'Animals information - Color: ' + this.color +
', Weight: ' + this.weight +
', Breed: ' + this.breed
);
}
toSleep(){
document.write('Sleeping a lot');
}
run(){
super.run();
document.write(' fast');
}
}
var dog = new Dog('Brown', 25, 'Doberman');
dog.toSleep();
document.write('<br>');
dog.run();
document.write('<br>');
dog.getInfo();
// you can test this code in: https://jsfiddle.net/