⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 17.04 - genrecatalog and scificatalog classes.js

📁 JS设计模式源代码
💻 JS
字号:
/* GenreCatalog class, used as a superclass for specific catalog classes. */var GenreCatalog = function() { // implements Catalog  this.successor = null;  this.catalog = [];};GenreCatalog.prototype = {  _bookMatchesCriteria: function(book) {    return false; // Default implementation; this method will be overriden in                  // the subclasses.  }  handleFilingRequest: function(book) {    // Check to see if the book belongs in this catagory.    if(this._bookMatchesCriteria(book)) {      this.catalog.push(book);    }    // Pass the request on to the next link.    if(this.successor) {      this.successor.handleFilingRequest(book);    }  },  findBooks: function(request) {    if(this.successor) {      return this.successor.findBooks(request);    }  },  setSuccessor: function(successor) {    if(Interface.ensureImplements(successor, Catalog) {      this.successor = successor;    }  }};/* SciFiCatalog class. */var SciFiCatalog = function() {}; // implements Catalogextend(SciFiCatalog, GenreCatalog);SciFiCatalog.prototype._bookMatchesCriteria = function(book) {  var genres = book.getGenres();  if(book.getTitle().match(/space/i)) {    return true;  }  for(var i = 0, len = genres.length; i < len; i++) {    var genre = genres[i].toLowerCase();    if(genres === 'sci-fi' || genres === 'scifi' || genres === 'science fiction') {      return true;    }  }  return false;};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -