Tuesday, June 26, 2007

Inheritance

Say you have an Employee "class" and a Manager "class" (which will inherit from Employee). First, create a constructor function with the definition of the employee, and likewise for the Manager. To create the inheritance link, set the prototype property of the Manger's constructor function to an employee object:

function Manager () {
this.reports = [];
}
Manager.prototype = new Employee;

No comments:

Pyjamas