Answers for "How to extend one class from another in javascript?"

1

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);
Posted by: Guest on April-24-2022

Code answers related to "How to extend one class from another in javascript?"

Code answers related to "Javascript"

Browse Popular Code Answers by Language