Vanguard Software
Forecasting & Planning Solutions
Home Products Solutions Services Customers Partners Company
 
Applying science to business management

contents.gifindex.gifprev1.gifnext1.gif

Accessing Object Properties

As you have already seen, you can access object properties by placing a period after the object name followed by the property name. For example, you can access the name property in the object stored in the variable named customer by using the expression

customer.name

An object property is a lot like a variable. That is, you can both write data to and read data from a property.

customer.name="John Doe";
say("Hello "+customer.name+".");

If you attempt to assign a value to a property that does not already exist, the property is automatically created. However, if you read a property that does not exist, the property is NOT created and the result null is returned.

var obj=new Object(); // create a new object
obj.x=12; // create property x and set = 12
var z=obj.y; // z = null, y is not created

You can also access properties using a syntax similar to what is used to access list elements. The following two expressions are equivalent:

customer.name
customer["name"]

The advantage to the second syntax is that you can choose the property name at run-time. For example,

var x="name";
customer[x]="John Doe";

See Also

for/in Loops

Deleting Properties

  Demand Planning  |  Financial Forecasting
Forecasting Software  |  Strategic Planning Software  |  Decision Tree Software
Decision Support Software  |  Expert System Software  |  Online Surveys

Contact Us  |  Terms of Use  |  Privacy Policy  |  Site Map
Vanguard Software
© 2011 Vanguard Software Corporation
Print this page   Email this page to a friend