-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.js
More file actions
130 lines (100 loc) · 2.15 KB
/
classes.js
File metadata and controls
130 lines (100 loc) · 2.15 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const student = {
name:"divisha",
age: 78,
printmarks: () =>{
console.log(this.age);
}
};
//special property of object is prototype(reference to object) that has variours method;
let emp = {
taxrate : 50,
caltax1(){
console.log(this.taxrate);
}
};
let karan = {
salary : 5000
};
karan.__proto__ = emp;
console.log(karan.caltax1());
let arjun = {
caltax1(){
console.log("your tax is 20%");//overridden
},
caltax2(){
console.log(33);
}
}
arjun.__proto__ = emp;
console.log(arjun.caltax1())
class car {
constructor(color){
console.log("i initialize the object and made by default if not made manually")
console.log(this.color)
this.color = color;
console.log(this.color)
}
start(){
console.log("start");
}//commas are not used for seperation in classes
end(){
console.log("end");
}
setbrand(brand){
this.brand = brand;
}
}
let fortuner = new car("blue");//object
fortuner.brand = "toyota";
console.log(fortuner.brand);
fortuner.setbrand("hello");
console.log(fortuner.brand);
fortuner.milage = 10;
console.log(fortuner.milage);
class parent{
constructor(x,name){
console.log("enter parent")
console.log("i am the parent of :",x)
this.species =name;
console.log("exit parent")
}
hello(){
console.log("i will be inherited");
}
over(){
console.log("jygjy");
}
eat(){
console.log("i want to eat something");
}
}
class child extends parent{
constructor(n,name){
console.log("enter child")//chile->parent
super(n,name);//parent class is called before child class in constructor
console.log("i am the child class")
console.log("exit child")
}
over(){
console.log("i will override");
}
eaten(){
super.eat();
}
}
let obj = new child("obj","molly");
console.log(typeof obj);
obj.hello();
obj.over();
console.log(obj.species);
obj.eaten();
obj.eat();
let a = 10;
let b = 20;
console.log(a+b);
try{
console.log(a+c);
} catch(err){
console.log(err);
}
console.log(a+b);