Java Reference
In-Depth Information
// Cinema type
function Cinema()
{
this.bookings = new Array();
}
This code defi nes the constructor. Inside the constructor, you initialize the bookings property that
holds all the CustomerBooking instance objects.
Next you need to add a way of making bookings for the cinema; for this you create the addBooking()
method.
cinema.prototype.addBooking = function(bookingId, customerName, film, showDate)
{
this.bookings[bookingId] = new CustomerBooking(bookingId,
customerName, film, showDate);
}
The method accepts four parameters, the details needed to create a new booking. Then, inside the
method, you create a new object of type CustomerBooking . A reference to this object is stored inside
the bookings array, using the unique bookingId to associate the place in which the new object is
stored.
Let's look at how you can access the items in the array. In the following method, called
getBookingsTable() , you go through each booking in the cinema and create the HTML
necessary to display all the bookings in a table.
Cinema.prototype.getBookingsTable = function()
{
var booking;
var bookingsTableHTML = “<table border=1>”;
for (booking in this.bookings)
{
bookingsTableHTML += “<tr><td>”;
bookingsTableHTML += this.bookings[booking].getBookingId();
bookingsTableHTML += “</td>”;
bookingsTableHTML += “<td>”;
bookingsTableHTML += this.bookings[booking].getCustomerName();
bookingsTableHTML += “</td>”;
bookingsTableHTML += “<td>”;
bookingsTableHTML += this.bookings[booking].getFilm();
bookingsTableHTML += “</td>”;
bookingsTableHTML += “<td>”;
bookingsTableHTML += this.bookings[booking].getShowDate();
bookingsTableHTML += “</td>”;
bookingsTableHTML += “</tr>”;
Search WWH ::




Custom Search