|
@@ -265,7 +265,7 @@ function getMagazinesInventory(): Array<Magazine> {
|
|
},
|
|
},
|
|
{
|
|
{
|
|
publisher: 'GSU',
|
|
publisher: 'GSU',
|
|
- title: 'Give Points',
|
|
|
|
|
|
+ title: 'Five Points',
|
|
}
|
|
}
|
|
];
|
|
];
|
|
}
|
|
}
|
|
@@ -286,16 +286,22 @@ function genericClassDemo() {
|
|
let bookShelf: Shelf<Book> = new Shelf<Book>();
|
|
let bookShelf: Shelf<Book> = new Shelf<Book>();
|
|
getBooksInventory().forEach(book => bookShelf.add(book));
|
|
getBooksInventory().forEach(book => bookShelf.add(book));
|
|
let firstBook: Book = bookShelf.getFirst();
|
|
let firstBook: Book = bookShelf.getFirst();
|
|
- console.log(firstBook);
|
|
|
|
|
|
+ // console.log(firstBook);
|
|
|
|
|
|
let magazineShelf: Shelf<Magazine> = new Shelf<Magazine>();
|
|
let magazineShelf: Shelf<Magazine> = new Shelf<Magazine>();
|
|
getMagazinesInventory().forEach(mag => magazineShelf.add(mag));
|
|
getMagazinesInventory().forEach(mag => magazineShelf.add(mag));
|
|
let firstMagazine: Magazine = magazineShelf.getFirst();
|
|
let firstMagazine: Magazine = magazineShelf.getFirst();
|
|
- console.log(firstMagazine);
|
|
|
|
|
|
+ // console.log(firstMagazine);
|
|
|
|
|
|
- let numberShelf: Shelf<number> = new Shelf<number>();
|
|
|
|
- [5, 10, 15].forEach(num => numberShelf.add(num));
|
|
|
|
- console.log(numberShelf);
|
|
|
|
|
|
+ // No longer works after constraining Shelf<T extends ShelfItem>.
|
|
|
|
+ // let numberShelf: Shelf<number> = new Shelf<number>();
|
|
|
|
+ // [5, 10, 15].forEach(num => numberShelf.add(num));
|
|
|
|
+ // console.log(numberShelf);
|
|
|
|
+ magazineShelf.printTitles();
|
|
|
|
+
|
|
|
|
+ // Since bookShelf is Shelf<Book>, softwareBook is a Book.
|
|
|
|
+ let softwareBook = bookShelf.find('Code Complete');
|
|
|
|
+ console.log(`${softwareBook.title} (${softwareBook.author})`);
|
|
}
|
|
}
|
|
|
|
|
|
false && bookDemo();
|
|
false && bookDemo();
|