JS Built-ins
Prototypesbeginner

Prototypes β€” Inheritance with extends

πŸ“– Usage Example
class Animal {
  constructor(name) { this.name = name; }
}
class Dog extends Animal {
  bark() { return 'woof'; }
}
new Dog('Rex').bark(); // 'woof'

extends creates a child class that inherits all of the parent's methods.

Creating Subclasses with extends

The extends keyword allows a class to inherit from another class. The subclass gets all the methods and properties of the parent class.

Challenge: Create a subclass that inherits methods from a parent class.

πŸ’‘ Hints (3)
  • β€’ extends creates a subclass relationship
  • β€’ Child class inherits all parent methods
  • β€’ instanceof returns true for parent class