HTML and CSS Reference
A literal object called soldier is defined with properties and methods.
The property name is separated from its value with a colon. The value is undefined
at this point.
The property is rank . Its value is a string, “captain”.
This property is picture ; its value is a JPEG file.
The property fallIn is assigned an anonymous function that will serve as a method
for this object.
The property fallOut is assigned an anonymous function that will server as anoth-
er method for this object.
The object's property name is assigned a value, “Tina Savage”. It is initially assigned
In this and the next line the value of the name and rank properties is printed.
A picture of the soldier is assigned to the img tag's src property and displayed in
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-
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.