Course contentsShow
← JavaScript
Lesson 774 of 2,72318. ClassesFree lesson

Calling Parent Methods with super

Using super.methodName() to invoke the parent's version of an overridden method.

Calling Parent Methods with super

You'll learn: How to call the parent class's version of a method from within an overridden child method using super.methodName().

The Core Idea

When you override a parent method in a child class, sometimes you want to extend the parent's behavior rather than completely replace it. The super keyword lets you explicitly invoke the parent's version of that method, allowing you to add your own logic before, after, or around the parent's implementation.

Think of it like customizing a family recipe: you follow your parent's original recipe (the parent method), but you add your own special ingredient at the end (additional child logic).

How It Works

After using super() in the constructor, you can call parent methods elsewhere using super.methodName():

class Animal {
  speak() {
    return "Some generic sound";
  }
}

class Dog extends Animal {
  speak() {
    const parentSound = super.speak(); // Call parent's speak()
    return `${parentSound}, but specifically: Woof!`;
  }
}

const dog = new Dog();
console.log(dog.speak()); 
// "Some generic sound, but specifically: Woof!"

Here, Dog doesn't ignore Animal's speak() method—it builds on it by calling super.speak() first, then adding its own twist.

You can also pass arguments to parent methods:

class Rectangle {
  getArea(multiplier = 1) {
    return this.width * this.height * multiplier;
  }
}

class Square extends Rectangle {
  getArea(multiplier) {
    const baseArea = super.getArea(multiplier);
    console.log(`Square area: ${baseArea}`);
    return baseArea;
  }
}

Key Takeaway: Use super.methodName() inside a child class method to call the parent's version of that same method, letting you extend functionality rather than completely replace it.