Querying and Setting Properties
To obtain the value of a property, use the dot (
.) or square bracket (
) operators described in Property Access Expressions. The left-hand side should be an expression
whose value is an object. If using the dot operator, the right-hand
must be a simple identifier that names the property. If using square
brackets, the value within the brackets must be an expression that
evaluates to a string that contains the desired property
// Get the "author" property of the book.
// Get the "surname" property of the author.
// Get the "main title" property of the book.
To create or set a property, use a dot or square brackets as you would to query the property, but put them on the left-hand side of an assignment expression:
// Create an "edition" property of book.
// Set the "main title" property.
In ECMAScript 3, the identifier that follows the dot operator
cannot be a reserved word: you cannot write
o.class, for example, because
for is a language keyword and
class is reserved for future use. If an
object has properties whose name is a reserved word, you must use
square bracket notation to access them:
o["class"]. ECMAScript 5 relaxes this
restriction (as do some implementations of ECMAScript
3) and allows reserved words to follow the dot.
When using square bracket notation, we’ve said that the expression ...