inheritance.js
class Shape {
area() { return 0; }
}
class Rect extends Shape {
constructor(w, h) { super(); this.w = w; this.h = h; }
area() { return this.w * this.h; }
}
class Square extends Rect {
constructor(side) { super(side, side); }
}
const shapes = [new Rect(2, 3), new Square(4)];
shapes.map((s) => s.area());
What to watch
Each instance is tagged with its class; super() chains constructors and area() dispatches to the right override.
Reading inheritance (polymorphism)on a page only gets you so far - code is a process, and the process happens at runtime where you can't normally see it. In NeonFlow, this exact program runs step by step: every call opens a frame, every branch picks a path, and every value moves through memory in front of you. That's the fastest way to actually understand how inheritance (polymorphism) works.
Run inheritance (polymorphism) yourself
Open NeonFlow, paste this code (or any of your own), and scrub through it one step at a time.
Open NeonFlow