jsverse
Advanced JavaScript / Classes

Classes

Syntax for building objects with shared behavior, on top of the same prototype chain.

A `class` is mostly a cleaner way to write what prototypes already do: methods defined on a class live on its `prototype`, shared by every instance rather than copied onto each one. `extends` links a subclass's prototype to its parent's, and `super()` calls the parent constructor so inherited fields get set up correctly.

Codeeditable — Run and Step both follow your edits
Loading...
Console
Output will appear here
Visualization
Result
Press Step to watch each line's result appear here
Why?

Dog.prototype's own prototype is Animal.prototype. Dog defines its own speak, so that's found first - if it didn't, the lookup would continue up to Animal's speak.