User-Defined Objects

Most of the objects discussed so far and those to be discussed in the rest of the book are defined in an HTML script. However, JavaScript provides a way that you can define your own objects with different properties. Each property can be assigned a value, just as with objects in HTML. The object constructor Object() is used to create user-defined objects using the following format:

						var userObj = new Object() 

After the object has been initialized, you can either add new objects to the existing object or add properties and their values. Consider an organization, the Acme Car Company, with the following five departments and two subdivisions:

Management

Research and Development

Finance

Production

Marketing

Sales

Fulfillment

To create ...

Get JavaScript Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.