The example in this article tells JavaScript to build its own object. Share to everyone for your reference, specific as follows:
<script type= ' text/javascript ' >//Build a customerbooking class//Constructor function customerbooking (bookingid,customername
, film,showdate) {this.bookingid = Bookingid;
This.customername = CustomerName;
This.film = film;
This.showdate =showdate;
//getbookingid method, somewhat peculiar CustomerBooking.prototype.getBookingId = function () {return this.bookingid;}//setbookingid method
CustomerBooking.prototype.setBookingId = function (bookingid) {this.bookingid = Bookingid;}
CustomerBooking.prototype.getCustomerName = function () {return this.customername;}
CustomerBooking.prototype.setCustomerName = function (customerName) {this.customername = CustomerName;}
CustomerBooking.prototype.getFilm = function () {return this.film;}
CustomerBooking.prototype.setFilm = function (film) {this.film = film;}
CustomerBooking.prototype.getShowDate = function () {return this.showdate;}
CustomerBooking.prototype.setShowDate = function (showdate) {this.showdate = showdate;}//Build a Cineme class, an array of properties that can save scheduled information FunctiOn Cinema () {this.bookings = new Array ();}//addbooking Method cinema.prototype.addBooking = function (bookingid,customername , film,showdate) {This.bookings[bookingid] = new customerbooking (bookingid,customername,film,showdate);}//
Getbookingstable Method 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></tr>"; } bookingstablehtml ="</table>";
return bookingstablehtml; //New Cinema object, which will be automatically generated by Addbooking Customerbooking object, saved to the Cinema object Bookingfilm properties,
Then call the Getbookingstable method to get the data information var bookingfilm = new Cinema ();
Bookingfilm.addbooking (123, "Jack", "Love Java", "1 May 2012");
Bookingfilm.addbooking (123, "Jack", "Love Java", "1 May 2012");
Bookingfilm.addbooking (122, "Jack", "Love Java", "1 May 2012");
Bookingfilm.addbooking (121, "Jack", "Love Java", "1 May 2012");
Bookingfilm.addbooking ("Jack", "Love Java", "1 May 2012");
Bookingfilm.addbooking (119, "Jack", "Love Java", "1 May 2012");
document.write (Bookingfilm.getbookingstable ());
</script>
For more on JavaScript related content to view the site topics: "JavaScript object-oriented Tutorial", "javascript json operation tips Summary", "JavaScript switching effects and techniques summary", " JavaScript Search Algorithm Skills summary, javascript error and debugging skills Summary, JavaScript data structure and algorithm skills summary, JavaScript traversal algorithm and skills summary and JavaScript mathematical Operational Usage Summary
I hope this article will help you with JavaScript programming.