Code:
function Person(name) {
this.name = name;
}
Person.prototype.getName = function() {
return this.name;
}
function Employee(name, salary) {
Person.call(this, name);
this.salary = salary;
}
Employee.prototype.__proto__ = Person.prototype;
Employee.prototype.getSalary = function() {
return this.salary;
}
function Executive(name, salary, bonus) {
Employee.call(this, name, salary);
this.bonus = bonus;
}
Executive.prototype.__proto__ = Employee.prototype;
Executive.prototype.getBonus = function() {
return this.bonus;
}
var workerbee = new Employee('Workerbee', 100000);
var hotshot = new Executive('Hotshot', 400000, 100000);
hotshot instanceof Executive => true
hotshot instanceof Employee => true
hotshot instanceof Person => true
workerbee instanceof Executive => false
workerbee instanceof Employee => true
workerbee instanceof Person => true
Picture:
Comments?
Other than use of __proto__ (bad! I know).