How to extend one class from another in javascript?
// Book parent class
class Book {
constructor(pages) {
this.pages = pages;
}
get getPages() {
return this.pages;
}
}
// Dictionary child class
class Dictionary extends Book {
constructor(pages, definitions) {
super(pages);
this.definitions = definitions;
}
set setDefinitions(definitions) {
this.definitions = definitions;
}
}
const webster = new Dictionary(530, 62500);
console.log(webster.getPages);
webster.setDefinitions = 470000;
console.log(webster.definitions);