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

JS實(shí)現(xiàn)簡(jiǎn)單的圖書館享元模式實(shí)例

 更新時(shí)間:2015年06月30日 12:13:44   作者:方方和圓圓  
這篇文章主要介紹了JS實(shí)現(xiàn)簡(jiǎn)單的圖書館享元模式,以一個(gè)圖書館存書借書的例子分析了圖書館享元模式的實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了JS實(shí)現(xiàn)簡(jiǎn)單的圖書館享元模式。分享給大家供大家參考。具體如下:

<!DOCTYPE html>
<html>
<head>
<title>享員模式</title>
</head>
<body>
<script>
 /*
  *flyweight 享員模式
  */
 //例子是一個(gè)圖書館存書借書 ->_->
 var Book = function(id, title, author, genre, pageCount, publisherId, ISBN, checkoutDate, checkoutMember /*還有一些*/){
  this.id = id;
  this.title = title;
  this.author = author;
  this.genre = this.genre;
  this.pageCount = pageCount;
  this.publisherId = publisherId;
  this.ISBN = ISBN;
  /*...*/
  this.checkoutDate = checkoutDate;
  this.checkoutMember = checkoutMember;
 };
 Book.prototype = {
  getTitle : function(){
   return this.title;
  },
  getAuthor : function(){
   return this.author;
  },
  getISBN : function(){
   return this.ISBN;
  },
  /*__more.._*/
  updateCheckoutStatus : function(booId,checkoutDate,checkoutMember){
   this.id = bookId;
   this.checkoutDate = checkoutDate;
   this.checkoutMember = checkoutMember;
   /*_more.._*/
  }
 };
 //下面介紹享元的版本;PS(使用了一個(gè)OBJ存書籍,這樣就可以存多的書)
 var BookFactory = (function(){
  var existingBooks = {},existingBook;
  return {
   createBook : function(title,author,genre,ISBN){
    existingBook = existingBooks[ISBN];
    if(existingBook){
     return existingBook;
    }else{
     var book = new Book(/*_moreData_bookInfo == _*/)
     return existingBooks[ISBN] = book;
    }
   }
  }
 })();
 var BookRecordManager = (function(){
  var bookRecordDatabase = {};
  return {
   addBookRecord : function(id,ISNB/* == */){
    var book = BookFactory.createBook(/**/);
    bookRecordDatabase[id] = {
     checkoutDate : checkoutDate,
     checkoutMember : checkoutMember
    };
   },
   updateCheckoutStatus : function(bookId,xx){
    bookRecordDatabase[bookId] = {
     xx : tt,
     oo : yy
    }
   },
   extend : function(){
    /*自定義各種公用方法了*/
   }
  }
 })();
</script>
</body>
</html>

希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

乌兰县| 南木林县| 田东县| 张家口市| 宣恩县| 乌海市| 淳化县| 延吉市| 台前县| 塔城市| 肇东市| 马山县| 抚远县| 紫金县| 金塔县| 香港| 兰坪| 依兰县| 望江县| 泸定县| 钟山县| 汨罗市| 柳江县| 隆回县| 铜陵市| 交城县| 彝良县| 商洛市| 时尚| 科技| 兴文县| 桃江县| 利辛县| 观塘区| 太和县| 精河县| 泰和县| 洛隆县| 秦皇岛市| 合江县| 巴林左旗|