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.




JavaScript Professional Projects
JavaScript Professional Projects
ISBN: 1592000134
EAN: 2147483647
Year: 2002
Pages: 130
Authors: Paul Hatcher

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net