JavaScript builds its own object sample _javascript tips

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.