-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
63 lines (48 loc) · 1.37 KB
/
script.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
// Person constructor
function Person(name){
this.name = name;
}
Person.prototype.Introduce = function(){
console.log('hello my name is '+this.name);
}
// Teacher constructor
function Teacher(name,branch){
Person.call(this,name);
this.branch = branch;
}
Teacher.prototype = Object.create(Person.prototype);
Teacher.prototype.constructor = Teacher;
Teacher.prototype.teach = function(){
console.log('I teach '+this.branch);
}
// Student constructor
function Student(name,number){
Person.call(this,name);
this.number = number;
}
Student.prototype = Object.create(Person.prototype);
Student.prototype.constructor = Student;
Student.prototype.study = function(){
console.log('my student number is '+ this.number + ' Ive already studied hard ');
}
// Headmaster Constructor
function Headmaster(name,branch){
Teacher.call(this,name,branch);
}
Headmaster.prototype = Object.create(Teacher.prototype);
Headmaster.prototype.constructor = Headmaster;
Headmaster.prototype.shareTask = function(){
console.log('Ive already shared all the work');
}
let p1 = new Person('çınar');
p1.Introduce();
let t1 = new Teacher('sadık','math');
t1.Introduce();
t1.teach();
let s1 = new Student('yiğit','100');
s1.Introduce();
s1.study();
let h1 = new Headmaster('ahmet','physics');
h1.Introduce(); // Person
h1.teach(); // Teacher
h1.shareTask(); // Headmaster