-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclasses.js
52 lines (39 loc) · 845 Bytes
/
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
class Human{
name;
color;
gender;
energy=100;
#birthDate;
constructor(name,color,gender,relgion,birthDate){
this.name=name;
this.color=color;
this.#birthDate=birthDate;
}
setBirthDate(dt){
this.#birthDate=dt;
}
getName(){return this.name}
static SayHello(){
console.log("hello world");
}
work(){
this.energy--;
}
}
var mahmoud=new Human('mahmoud','red','male','muslim',new Date());
Human.SayHello();
//this throws an error, need to be handled through a function
//mahmoud.#birthDate=new Date("1986-12-6");
console.log(mahmoud.getName());
class Student extends Human{
id;
constructor(){
super('ahmed');
id=0;
}
work(){
super.work();
this.energy-=60;
}
}
var student=new Student('ahmed','x','male');