Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- // Classical OOP
- // Inherit
- Function.prototype.inherit = function (parent) {
- this.prototype = new parent();
- this.prototype.constructor = parent;
- }
- // Base class
- function Human(fname, lname, age)
- {
- this.fname = fname;
- this.lname = lname;
- this.age = age;
- }
- // Student -> Human
- function Student(fname, lname, age, grade) {
- Human.call(this, fname, lname, age);
- this.grade = grade;
- }
- Student.inherit(Human);
- Student.prototype.introduce = function () {
- return "Hello! My name is " + this.fname + " " + this.lname + ", my age is: " + this.age + " grade: " + this.grade;
- }
- // Teacher -> Human
- function Teacher(fname, lname, age, speciality) {
- Human.call(this, fname, lname, age);
- this.speciality = speciality;
- }
- Teacher.inherit(Human);
- Teacher.prototype.introduce = function () {
- return "Hello! My name is " + this.fname + " " + this.lname + ", my age is: " + this.age + " my speciality is: " + this.speciality;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement