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;

Javascript Object Constructors

A constructor is a function that you intend to use to create objects. In the following example, car is the constructor and mycar is the object:

function car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}

mycar = new car("Eagle", "Talon TSi", 1993);


Pyjamas