-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path86Class&ExtendsKeywoard.js
58 lines (45 loc) · 1002 Bytes
/
86Class&ExtendsKeywoard.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
// class practice and extends keywoard
class Animal {
constructor(name, age){
this.name = name;
this.age = age;
}
eat(){
return `${this.name} is eating`;
}
isSuperCute(){
return this.age <= 1;
}
isCute(){
return true;
}
}
// const animal1 = new Animal("tom", 2);
// console.log(animal1);
// console.log(animal1.eat());
// console.log(animal1.isSuperCute());
// class and extend
// Animal is parent class
// Dog is sub class
class Dog extends Animal{
}
const tommy = new Dog("tommy", 3);
console.log(tommy);
console.log(tommy.isCute());
// with the help of "extend" keyword we need not to
// write this much of code
// class Dog{
// constructor(name, age){
// this.name = name;
// this.age = age;
// }
// eat(){
// return `${this.name} is eating`;
// }
// isSuperCute(){
// return this.age <= 1;
// }
// isCute(){
// return true;
// }
// }