-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClasses.js
81 lines (54 loc) · 1.15 KB
/
Classes.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
70
71
72
73
74
75
76
77
78
79
80
81
//object oriented programming concepts
//Inheritance => just revileelated information to end user
//Polimorphysome => put related information together
//Encapsulation => code reusalibility
//Abstaction => expose related thing
// function Animal(type){
// }
// Animal()
class Animal{
constructor(type){
this.type=type;
console.log(type);
//call only one when we create instance
}
set type(value){
this._type=value.toUpperCase()
}
get type(){
return this._type
}
makesound(){
console.log(this.type)
if(this.type==='DOG'){
console.log('bow bow') ;
}
else{
console.log('meow')
}
}
static a=1;
static sayHello(){
console.log('hello');
}
};
class Dog extends Animal{
constructor(){
super('Dog')
}
makesound(){
// console.log('Bow vow')
super.makesound();
}
}
const d=new Dog()
d.makesound();
// console.log(Animal.sayHello())
//instance of the object
// const a= new Animal('Dog');
// console.log(Animal.a)
// a.makesound();
// console.log(a.type);
// //instance of the object
// const b= new Animal('Cat');
// b.makesound();