Skip to the workspace
Pebellslearn by building
Classes  ›  Lesson

Inheritance and super

Classes 12 min

javascript / Inheritance and super

Explore each scene at your own pace.

01 · Inheritance and super

Inheritance and super

Inheritance and super

extends connects class inheritance, and super calls or accesses parent behavior. A derived constructor must initialize this through super before using this.

Reuse a parent’s initialization, then add the child’s specific state.

See the mechanism

Walk through the modelInheritance and superAuthored snapshots of the example; use Run below to test the code.
Statenew FeaturedArticle("Morning")
The derived instance needs parent initialization.
1 of 3

Follow one example

javascript

super(title) runs the parent constructor for the new derived instance. The child then adds featured. Its prototype chain makes parent methods available when not overridden. Inheritance models an is-a relationship; composing separate behaviors is often clearer when one object merely uses another.

Predict, change and check

Predict: What fails if this.featured = true is placed before super(title)?

Test your explanation: Test the constructor order, then restore it. Add a parent method and compare an inherited call with a deliberate child override.

The tasks below ask you to explain that result and apply the idea to different inputs.

Apply and distinguish

Extend behavior without confusing storage

extends establishes the class and prototype relationships used for inheritance. A derived constructor must call super before using this. An overridden method can call super.method to reuse parent behavior, but that is a specific method lookup, not a second independent object embedded in the instance.

Use inheritance for a compatible behavioral relationship rather than to avoid writing two similar lines. An inherited method can still operate on the derived receiver. Test the base behavior, the override and an inherited property lookup, and inspect which fields are actually own properties of the instance.

Check your understanding: State the input contract, identify the operation that changes the result, and give one boundary input that would distinguish the correct rule from the mistake described above.

Scene 1 of 2
Project context and further resources
Additional resources
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.