crossbind
GitHub

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 area is virtual. largerArea takes two Shape references; handed a Circle and a Square, each call to area() runs that class's own code, as it would in C++.

A class binds with one base; a second base class is left out. The hierarchy itself stays in C++: a JavaScript class cannot extend Shape to override its methods.

Try it
Find the radius at which the circle becomes the larger of the two.
Open in playground
Runs without a compile until the C++, Rust, packages or imports change.
Press Run, or Ctrl+Enter, to run main.js.
Type to search every guide page and section.
↑↓ navigate↵ openesc close