17.02 - publiclibrary class with hard-coded catalogs.js
来自「JS设计模式源代码」· JavaScript 代码 · 共 31 行
JS
31 行
/* PublicLibrary class, with hard-coded catalogs for genre. */var PublicLibrary = function(books) { // implements Library this.catalog = {}; this.biographyCatalog = new BiographyCatalog(); this.fantasyCatalog = new FantasyCatalog(); this.mysteryCatalog = new MysteryCatalog(); this.nonFictionCatalog = new NonFictionCatalog(); this.sciFiCatalog = new SciFiCatalog(); for(var i = 0, len = books.length; i < len; i++) { this.addBook(books[i]); }};PublicLibrary.prototype = { findBooks: function(searchString) { ... }, checkoutBook: function(book) { ... }, returnBook: function(book) { ... }, addBook: function(newBook) { // Always add the book to the main catalog. this.catalog[newBook.getIsbn()] = { book: newBook, available: true }; // Try to add the book to each genre catalog. this.biographyCatalog.handleFilingRequest(newBook); this.fantasyCatalog.handleFilingRequest(newBook); this.mysteryCatalog.handleFilingRequest(newBook); this.nonFictionCatalog.handleFilingRequest(newBook); this.sciFiCatalog.handleFilingRequest(newBook); }};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?