JavaScript `super` Semantics
`super` lets a class or object method access members through its parent in the prototype chain, while keeping the current object as the receiver. In a derived class constructor, `super(...)` invokes the parent constructor and initializes `this`.
`super` has two main forms: `super.property` and `super(...)`. The call form is only valid in a derived class constructor; the property form is used in methods, including static methods.
For `super.method()`, JavaScript looks up `method` starting from the prototype associated with the current method, then calls it with the current `this`. This is why an inherited method can use the derived instance's fields. The method's home object determines where lookup begins; `super` does not simply mean “the parent object.”
A derived constructor must call `super(...)` before it accesses `this`. That call runs the parent constructor and initializes the derived instance. If a derived constructor has no explicit body, JavaScript supplies a default constructor that forwards its arguments to the parent.
The `super` binding is tied to the method's definition, not to the object on which the method is later called. Arrow functions created inside a method inherit its `super` and `this` bindings. `super` is not a general-purpose variable, so it cannot be used in an ordinary function or as a standalone value.
Key points
- `super.method()` looks up the method through the prototype chain and calls it with the current `this`.
- In a derived constructor, `super(...)` must run before `this` is accessed.
- A method's home object determines the starting point for `super` property lookup.
- `super` works in static methods as well as instance methods.
- `super.property` and `super(...)` are distinct forms with different allowed contexts.
Interview questions
What does `super.method()` do in an overridden instance method?
It looks for `method` starting from the prototype above the method's home object. If found, it calls that method with the current `this`, which is usually the derived instance. That lets the parent implementation access fields on the derived object. It does not create or retrieve a separate parent instance.
Why must a derived constructor call `super()` before using `this`?
A derived constructor begins without an initialized `this` binding. Calling `super(...)` runs the parent constructor and establishes the instance for the derived constructor to use. Attempting to read or write `this` first throws a `ReferenceError`. A derived constructor can instead return an object explicitly, but that is a special case rather than the usual pattern.
Does `super` mean the same thing as `Parent.prototype`?
No. `super` is a special syntax whose property lookup starts at the prototype associated with the method's home object. The receiver for a call remains the current `this`. An explicit `Parent.prototype.method.call(this)` names a particular prototype and can behave differently if the relevant prototype chain is changed.
Can `super` be used in a static method, and what does it refer to there?
Yes. In a static method, `super.property` looks up through the constructor's prototype chain rather than the instance-prototype chain. The call still uses the current `this`, which is typically the derived class constructor. This makes it possible for a derived static method to invoke or read an inherited static member.
What happens when assigning to `super.x`?
The property lookup for the assignment uses the `super` base, but the receiver is the current `this`. The assignment therefore does not simply mutate a property on the parent prototype. Depending on the property descriptor and receiver, it may invoke an inherited setter or create/update a property on the receiver; a non-writable inherited data property can prevent the assignment.