Java Reference
In-Depth Information
}
bookingsTableHTML += “</table>”;
return bookingsTableHTML;
}
You can access each booking by its unique bookingId , but what you want to do is simply loop through
all the bookings for the cinema, so you use a for...in loop, which loops through each item in the
items array. Each time the loop executes, booking will be set by JavaScript to contain the bookingId
of the next booking; it doesn't contain the item itself but its associated keyword.
Since you have the associated keyword, you can access the item objects in the array like this:
this.bookings[booking]
Remember that this refers to the object instance of your reference type. You then use the
CustomerBooking object's get methods to obtain the details for each booking. Finally, on the last line,
you return the HTML — with your summary of all the bookings — to the calling code.
Let's put this all together in a page and save the page as ch5_examp8.htm .
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Chapter 5: Example 8</title>
</head>
<body>
<h2>Summary of bookings</h2>
<script type=”text/javascript”>
// CustomerBooking type
function CustomerBooking(bookingId, customerName, film, showDate)
{
this.customerName = customerName;
this.bookingId = bookingId;
this.showDate = showDate;
this.film = film;
}
CustomerBooking.prototype.getCustomerName = function()
{
return this.customerName;
}
CustomerBooking.prototype.setCustomerName = function(customerName)
{
this.customerName = customerName;
}
CustomerBooking.prototype.getShowDate = function()
Search WWH ::




Custom Search