HTML and CSS Reference
In-Depth Information
EXPLANATION
1
A literal object called
soldier
is defined with properties and methods.
2
The property
name
is separated from its value with a colon. The value is
undefined
at this point.
3
The property is
rank
. Its value is a string, “captain”.
4
This property is
picture
; its value is a JPEG file.
5
The property
fallIn
is assigned an anonymous function that will serve as a method
for this object.
6
The property
fallOut
is assigned an anonymous function that will server as anoth-
er method for this object.
7
The object's property
name
is assigned a value, “Tina Savage”. It is initially assigned
“undefined”.
8
In this and the next line the value of the
name
and
rank
properties is printed.
9
A picture of the soldier is assigned to the
img
tag's
src
property and displayed in
the document.
10
The method for the object,
fallIn()
, is called. Note that by appending the () oper-
ator to the
fallIn
property, the function assigned to it on line 5 is called and exe-
cuted.
11
The method for the object,
fallOut()
, is called. By appending the () operator to the
fallOut
property, the function assigned to it on line 6 is called and executed. The
output is shown in Figure 8.8.
Figure 8.8
A literal object with properties and methods.