Java Reference
In-Depth Information
CustomerBooking.prototype.setFilm = function(film)
{
this.film = film;
}
CustomerBooking.prototype.getBookingId = function()
{
return this.bookingId;
}
CustomerBooking.prototype.setBookingId = function(bookingId)
{
this.bookingId = bookingId;
}
var firstBooking = new CustomerBooking(1234,
“Robert Smith”,”Raging Bull”, “25 July 2004 18:20”);
var secondBooking = new CustomerBooking(1244,
“Arnold Palmer”,”Toy Story”, “27 July 2004 20:15”);
document.write(“1st booking persons name is “ +
firstBooking.getCustomerName() + “<br />”);
document.write(“2nd booking persons name is “ +
secondBooking.getCustomerName());
</script>
</body>
</html>
At the top of the page is the <script /> element, inside of which is the code that defi nes your refer-
ence type. You must include type defi nition code in every page that uses your type to create objects. For
convenience, you may therefore decide to put your defi nitions in a separate fi le and import that fi le into
each page that uses the reference type. You can do this using the <script /> element, but instead of
putting the code inside the open and close tags, you'll use the script element's src attribute to point to
the fi le containing the JavaScript. For example, if you create a fi le called MyCinemaBookingTypes.js
and put your type code in there, you can import it into a page as shown here:
<script src=”MyCinemaBookingTypes.js”></script>
The src attribute points to the URL of your JavaScript fi le containing your type defi nition, which in
this case assumes the .js fi le is in the same directory as your page.
An Array of Items
So far you have a reference type for items that you can put a single booking into, but no type represent-
ing all the bookings taken by a cinema. So how can you create a cinema type that supports the storage
of zero or more items? The answer is using an array, which we discussed earlier in this chapter and in
Chapter 3.
Let's start by defi ning this new type, called Cinema , and add to the script block with the
CustomerBooking defi nition.
Search WWH ::




Custom Search