JavaScript › Classes & Class Syntax
How does method overriding with super work in JavaScript classes?
AdvancedAnswer
A subclass can redefine a parent's method by declaring one with the same name; calling super.methodName() from inside the override lets you still invoke the parent's original implementation, typically to extend rather than fully replace it.
class Shape {
describe() { return 'A shape'; }
}
class Circle extends Shape {
describe() { return super.describe() + ', specifically a circle'; }
}
new Circle().describe(); // 'A shape, specifically a circle'Real-world example Extending a base Logger class's log() method to add a timestamp prefix while still writing the original message.