I'm trying to figure out the correct use of inheritance. In the code below I'm trying to instantiate my ReadingMaterial
class, and make an array of books and magazines, inheriting from ReadingMaterial
. Am I using inheritance correctly here?
// Define our class with constructor
class ReadingMaterial {
constructor(author, type, price, title){
this.author = author;
this.type = type;
this.price = price;
this.title = title;
}
}
// variable books containing 2 different books
var books = [
new ReadingMaterial("Lars Tvede", "Fagliteratur", "399kr","Supertrends"),
new ReadingMaterial("Rasmmus Tantholdt", "Faglitteratur","249kr","Med åbne øjne"),
new ReadingMaterial("Jussi Alder", "Skønlitteratur", "349kr","Offer 2117")
];
// feature that allows you to type `showMagazines();` in the console
// so we can see our magazines
function showBooks (){
console.log(books);
};
// variable magazine containing 2 different magazines
var magazine = [
new ReadingMaterial("Euroman", "Magasin", "99kr","Mick Øgendahl"),
new ReadingMaterial("Alt for damerne", "Magasin", "149kr","Boligindretning")
];
// feature that allows you to type `showMagazines();` in the console
// so we can see our magazines
function showMagazines() {
console.log(magazine);
};