最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JavaScript構建自己的對象示例

 更新時間:2016年11月29日 10:44:26   作者:牛逼的霍嘯林  
這篇文章主要介紹了JavaScript構建自己的對象,結合實例形式分析了javascript自定義類的定義與對象的實例化相關操作技巧,需要的朋友可以參考下

本文實例講述了JavaScript構建自己的對象。分享給大家供大家參考,具體如下:

<script type='text/javascript'>
//構建一個CustomerBooking類
//構造函數
function CustomerBooking(bookingId,customerName,film,showDate){
  this.bookingId = bookingId;
  this.customerName = customerName;
  this.film = film;
  this.showDate =showDate;
}
//getBookingId方法,有點奇特
CustomerBooking.prototype.getBookingId = function(){
  return this.bookingId;
}
//setBookingId方法
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;
}
//構建一個cineme類,屬性為數組,可以保存預定信息
function cinema(){
  this.bookings = new Array();
}
//addBooking方法
cinema.prototype.addBooking = function(bookingId,customerName,film,showDate){
  this.bookings[bookingId] = new CustomerBooking(bookingId,customerName,film,showDate);
}
//getBookingsTable方法
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;
}
//新建cinema對象就可以了,這里會通過addBooking自動生成customerBooking對象,
保存到cinema對象bookingFilm的屬性當中,然后調用getBookingsTable方法來獲取數據信息
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(120,"Jack","Love Java","1 May 2012");
bookingFilm.addBooking(119,"Jack","Love Java","1 May 2012");
document.write(bookingFilm.getBookingsTable());
</script>

更多關于JavaScript相關內容可查看本站專題:《javascript面向對象入門教程》、《JavaScript中json操作技巧總結》、《JavaScript切換特效與技巧總結》、《JavaScript查找算法技巧總結》、《JavaScript錯誤與調試技巧總結》、《JavaScript數據結構與算法技巧總結》、《JavaScript遍歷算法與技巧總結》及《JavaScript數學運算用法總結

希望本文所述對大家JavaScript程序設計有所幫助。

相關文章

最新評論

黔西县| 周口市| 阳高县| 凤阳县| 重庆市| 曲靖市| 娄底市| 澜沧| 赤水市| 马山县| 策勒县| 彰武县| 上高县| 丰宁| 黑河市| 奉贤区| 广安市| 武川县| 鸡东县| 扬州市| 潜江市| 元谋县| 贡山| 旬邑县| 青海省| 铁岭市| 柞水县| 皮山县| 江北区| 全州县| 太康县| 文成县| 渭源县| 桂东县| 汝阳县| 牡丹江市| 湖口县| 呼图壁县| 南和县| 澄江县| 交城县|