crossbind
GitHub

A class

A C++ class arrives as a JavaScript class: new runs its constructor and its public methods are methods.

native.h declares Counter under a function like the last lesson's. await new Counter(41) runs the C++ constructor; increment and value are its public methods, and current, being private, stays inside C++.

The object lives in C++ and JavaScript holds a handle to it. The garbage collector frees it once the handle is gone; Object lifetime shows how to free it sooner.

Try it
Start a second counter at 100, increment it twice and print both values.
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