JS Built-ins
Prototypesintermediate

Prototypes β€” super.method() calls parent

πŸ“– Usage Example
class Animal { greet() { return 'Hello from animal'; } }
class Dog extends Animal {
  greet() { return super.greet() + ' and dog'; }
}
new Dog().greet(); // 'Hello from animal and dog'

super.method() calls the parent's version of an overridden method.

Calling Parent Methods with super.method()

The super keyword can be used to call parent methods, not just the constructor. This is useful when you want to extend parent behavior instead of replacing it completely.

Challenge: Override a method but call the parent's version from within the override using super.method().

πŸ’‘ Hints (3)
  • β€’ super.methodName() calls the parent version
  • β€’ Useful for extending rather than replacing behavior
  • β€’ super preserves the this context