HTML and CSS Reference
In-Depth Information
The owner has an address field that contains its set of property/value pairs.
This property will act as the object's method. It is assigned an inline function de-
fined to display properties of the object.
With object literals there is no constructor function. This line assigns a value to
an undefined Car property called make .
This Car's year property is assigned a new value.
The Car object's price property, originally undefined, is assigned a value.
The Car object's method called details() is called to display the properties of the
object. Be sure to observe the syntax differences; that is, an equals sign rather than
colon between property and value, and an optional semicolon rather than comma
at the end of the assignment. The output is shown in Figure 8.9.
Figure 8.9 Nesting property/value pairs in an object literal. Output of Example 8.8
literal objects.
Manipulating Objects
8.4.1 The with Keyword
The with keyword is used as a kind of shorthand for referencing an object's properties or
methods. The object specified as an argument to with becomes the current object for the
duration of the block that follows. The properties and methods for the object can be
used without naming the object or using the dot syntax. A caveat: This shorthand
might save typing, but it will also take a lot longer to run because JavaScript checks
each variable within the with block to see whether or not it is a property of the object
it references.
Search WWH ::

Custom Search