We've created our first wasm module in a similar fashion to coming up with a new product design. Now, it's time to see how our 'customers' will interact with this 'product'. As a professional web developer, you already know that JavaScript is the primary language for the web. WebAssembly provides special JavaScript APIs so that developers like us can interact with wasm modules seamlessly.
To call functions from wasm modules with JavaScript, we first need to fetch the wasm module and compile it using the WebAssembly JavaScript API. Once the module is compiled, we can instantiate it. At instantiation, JavaScript receives an exports object, which includes the functions that our wasm module has made available to JavaScript. We can then call these functions like any normal JavaScript function.
It might seem a bit tricky, but if you've ever orchestrated a marketing campaign where you needed to create different channels to reach your customers, it's pretty similar. The JavaScript APIs are like different marketing channels, and the wasm module is your product. It's all about creating a successful connection! Stay tuned to learn how to use JavaScript to call functions in a wasm module.
xxxxxxxxxx
using namespace std;
int main() {
// TODO: Add some C++ logic here
}