-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritExample.js
More file actions
53 lines (41 loc) · 1.06 KB
/
inheritExample.js
File metadata and controls
53 lines (41 loc) · 1.06 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
/* Person-->Student Person-->Teacher
Person ;name Introduce() -->Teacher,Headmaster
Student: name Introduce()+ number study()
Teacher:name Introduce() + branch teach()
*/
//Person Constructor
function Person(name) {
this.name = name;
}
Person.prototype.Introduce = function () {
console.log("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.class = function () {
console.log("Im " + this.number);
};
//Outputs
let p1 = new Person("Cemre");
p1.Introduce();
let t1 = new Teacher("Snm", "bio");
t1.Introduce();
t1.teach();
let s1 = new Student("Emre", 2);
s1.Introduce();
s1.class();