-
Notifications
You must be signed in to change notification settings - Fork 0
/
person.js
47 lines (44 loc) · 1.41 KB
/
person.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
function Person(firstName, lastName, age) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.getFullName = function () {
return this.firstName +" "+ this.lastName;
}
this.getInfo = function () {
return "My name is "+this.getFullName();
}
}
function Student(firstName, lastName, age, department, number) {
this.students = [];
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.department = department;
var matricNumber = number;
this.getMatricNumber = function () {
return matricNumber;
};
//Inheriting method and overriding getInfo() from the Person class
Student.prototype.getInfo = function () {
return "My name is "+this.getFullName()+" and am a student in the department of "+this.department;
};
}
function Employee(firstName, lastName, age, job, salary) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.job = job;
this.salary = salary;
}
//inheriting from the super class Person
Student.prototype = new Person();
Employee.prototype = new Person();
//Create instance of class Students
var student1 = new Student("Jorg", "Are", 18, "Computer Science");
var student2 = new Student("John", "Marley", 29, "Mathematics");
Console.log(student1.getInfo());
//Create instance of class Employee
var employee1 = new Employee("John", "Smith", 35,"Programmer", 56000);
var p1 = new Person("a", "b", 23);
Console.log(student1.getFullName());