Visit Mozilla.org

Core JavaScript 1.5 Guide:The Employee Example

From MDC


[edit] The Employee Example

The remainder of this chapter uses the employee hierarchy shown in the following figure.

Image:hier01.gif

Figure 8.1: A simple object hierarchy

This example uses the following objects:

  • Employee has the properties name (whose value defaults to the empty string) and dept (whose value defaults to "general").
  • Manager is based on Employee. It adds the reports property (whose value defaults to an empty array, intended to have an array of Employee objects as its value).
  • WorkerBee is also based on Employee. It adds the projects property (whose value defaults to an empty array, intended to have an array of strings as its value).
  • SalesPerson is based on WorkerBee. It adds the quota property (whose value defaults to 100). It also overrides the dept property with the value "sales", indicating that all salespersons are in the same department.
  • Engineer is based on WorkerBee. It adds the machine property (whose value defaults to the empty string) and also overrides the dept property with the value "engineering".

The rest of the example:


« Previous Next »