Team LiB
Previous Section Next Section

Object Properties

Objects are not only another data type. Instances of objects have methods and properties that are part of their definition. Object properties can be any of the three primitive data types, or any of the abstract data types, such as another object. Object properties are usually variables that are used internally in the object's methods, but can also be globally visible variables that are used throughout the page.

The syntax for adding a property to an object is

<object name>.<property name> = <property value>;

The object's name is followed by a dot and then the property name. At this point, the object's property can be used just like any other variable—to assign values to or read values from memory. Following is a simple example to demonstrate what I mean:

var myCar = new Car();


myCar.year = 2005;

In this case, the instance of the object type Car, myCar, has a property named year that is being assigned the value 2005. An object's property is a local variable and can vary between object instances.


Team LiB
Previous Section Next Section