-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreation.js
More file actions
96 lines (81 loc) · 2.82 KB
/
creation.js
File metadata and controls
96 lines (81 loc) · 2.82 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
class Person{
constructor(firstName, lastName, age, gender) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.gender = gender;
}
fullName() {
return `${this.firstName} ${this.lastName}`;
}
communicate() {
console.log('Communicating');
}
eat() {
console.log('Eating');
}
sleep() {
console.log('Sleeping');
}
}
class Doctor extends Person {
constructor(firstName, lastName, age, gender, specialization) {
super(firstName, lastName, age, gender);
this.specialization = specialization;
}
diagnose() {
console.log('Diagnosing');
}
}
class Student extends Person {
constructor(firstName, lastName, age, gender, degree) {
super(firstName, lastName, age, gender);
this.degree = degree;
}
study() {
console.log('Studying');
}
}
class Professor extends Person {
constructor(firstName, lastName, age, gender, subject) {
super(firstName, lastName, age, gender);
this.subject = subject;
}
teach() {
console.log('Teaching')
}
}
class GraduateStudent extends Student {
constructor(firstName, lastName, age, gender, degree, graduateDegree) {
super(firstName, lastName, age, gender, degree);
this.graduateDegree = graduateDegree;
}
research() {
console.log('Researching')
}
}
const person = new Person('foo', 'bar', 21, 'gender');
console.log(person instanceof Person); // logs true
person.eat(); // logs 'Eating'
person.communicate(); // logs 'Communicating'
person.sleep(); // logs 'Sleeping'
console.log(person.fullName()); // logs 'foo bar'
const doctor = new Doctor('foo', 'bar', 21, 'gender', 'Pediatrics');
console.log(doctor instanceof Person); // logs true
console.log(doctor instanceof Doctor); // logs true
doctor.eat(); // logs 'Eating'
doctor.communicate(); // logs 'Communicating'
doctor.sleep(); // logs 'Sleeping'
console.log(doctor.fullName()); // logs 'foo bar'
doctor.diagnose(); // logs 'Diagnosing'
const graduateStudent = new GraduateStudent('foo', 'bar', 21, 'gender', 'BS Industrial Engineering', 'MS Industrial Engineering');
// logs true for next three statements
console.log(graduateStudent instanceof Person);
console.log(graduateStudent instanceof Student);
console.log(graduateStudent instanceof GraduateStudent);
graduateStudent.eat(); // logs 'Eating'
graduateStudent.communicate(); // logs 'Communicating'
graduateStudent.sleep(); // logs 'Sleeping'
console.log(graduateStudent.fullName()); // logs 'foo bar'
graduateStudent.study(); // logs 'Studying'
graduateStudent.research(); // logs 'Researching'