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

JavaScript構(gòu)建自己的對象示例

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

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

<script type='text/javascript'>
//構(gòu)建一個CustomerBooking類
//構(gòu)造函數(shù)
function CustomerBooking(bookingId,customerName,film,showDate){
  this.bookingId = bookingId;
  this.customerName = customerName;
  this.film = film;
  this.showDate =showDate;
}
//getBookingId方法,有點(diǎn)奇特
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;
}
//構(gòu)建一個cineme類,屬性為數(shù)組,可以保存預(yù)定信息
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的屬性當(dāng)中,然后調(diào)用getBookingsTable方法來獲取數(shù)據(jù)信息
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>

更多關(guān)于JavaScript相關(guān)內(nèi)容可查看本站專題:《javascript面向?qū)ο笕腴T教程》、《JavaScript中json操作技巧總結(jié)》、《JavaScript切換特效與技巧總結(jié)》、《JavaScript查找算法技巧總結(jié)》、《JavaScript錯誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運(yùn)算用法總結(jié)

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

相關(guān)文章

最新評論

彰化市| 天峻县| 九江市| 霍山县| 叙永县| 普定县| 韶关市| 大埔县| 榕江县| 安徽省| 乌苏市| 岳阳市| 新闻| 萍乡市| 纳雍县| 金塔县| 防城港市| 卓尼县| 枞阳县| 新建县| 永城市| 贵州省| 晋中市| 泰州市| 镇平县| 阿克陶县| 聊城市| 武宣县| 登封市| 乐平市| 五台县| 彰化市| 天等县| 莒南县| 新建县| 丹东市| 页游| 加查县| 谢通门县| 南丹县| 宿松县|