Prototypal Inheritance with call()
by Florian Bar
JavaScript
function Person(first_name, last_name, age) {
this.first_name = first_name;
this.last_name = last_name;
this.age = age;
}
Person.prototype.getFullName = function() {
return this.first_name + ' ' + this.last_name;
};
function Teacher(first_name, last_name, age, school, subject) {
Person.call(this, first_name, last_name, age);
this.school = school;
this.subject = subject;
}
Teacher.prototype = Object.create(Person.prototype);
Teacher.prototype.constructor = Teacher;
var tom = new Teacher("Tom", "Jones", 30, "TV High", "Mathematics");
alert( tom.getFullName() );