Java Reference
In-Depth Information
Accessing Object's Properties
You can access properties of an object using property accessor expressions using one of
the two syntax:
Using the Dot Notation
Using the Bracket Notation
The dot notation uses the following syntax:
objectExpression.property
The objectExpression is an expression that evaluates to the reference to the object
and the property is the property name.
The bracket notation uses an array-like syntax:
objectExpression[propertyExpression]
The objectExpression is an expression that evaluates to the reference to the object.
It is followed with an opening bracket and a closing bracket. The propertyExpression is
an expression that is convertible to a string and that is the property name being accessed.
if the property name contains whitespaces or stored in a variable, you must use the
bracket notation, not the dot notation, to access the property.
Tip
Consider the following object from the previous section:
// An object with whitespaces in the property names
var redColor = {"red value": 1.0,
green: 0.0,
"black Value": 0.0,
alpha: 1.0};
The following statement reads the value of the alpha property of the object into a
variable named alphaValue :
// Assigns 1.0 to alphaValue
var alphaValue = redColor.alpha;
If the property accessor expression appears on the right side of the assignment
operator, you are setting a new value for the property. The following statement sets the
alpha property of the redColor object to 0.5:
// Make the color semi-transparent
redColor.alpha = 0.5;
 
 
Search WWH ::




Custom Search