crossbind
GitHub
TUTORIAL · STEP 5 OF 7

Inheritance

A class hierarchy keeps its shape in JavaScript: a derived object goes wherever its base class is expected.

Circle and Square derive from Shape, whose methods are virtual. describe takes a const Shape &; handed a Circle, its call to area() runs Circle::area(), as it would in C++.

instanceof follows the hierarchy too: a Circle is a Module.Shape. Single inheritance with virtual methods binds; multiple inheritance does not.

Try it
Add a Triangle with a base and a height, and describe one from main.js.
Runs without a compile until you edit the C++.
Console
Press Run, or Ctrl+Enter, to run main.js.
Type to search every guide page and section.
↑↓ navigate↵ openesc close