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 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 Shape. Single inheritance with virtual methods binds; multiple inheritance does not.

The hierarchy itself stays in C++: a JavaScript class cannot extend Shape to override its virtual methods.

Try it
Add a C++ class Triangle with a base and a height to native.h and native.cpp, and describe one from main.js.
Open in playgroundRuns without a compile until the C++, Rust, packages or imports change.
Console
Press Run, or Ctrl+Enter, to run main.js.
Type to search every guide page and section.
↑↓ navigate↵ openesc close