crossbind
GitHub
TUTORIAL · STEP 6 OF 7

Callbacks

A function pointer parameter takes a JavaScript function, and C++ calls it like any other.

countdown calls its Visitor once for every number, and each call runs the arrow function from main.js. applyTwice uses what its Transform returns.

Each JavaScript function handed to C++ holds a slot in the module until Module.releaseCallback(fn) frees it, so release a function once C++ no longer needs it.

Try it
Pass applyTwice a function that squares its argument and check the result.
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