Created
December 15, 2025 18:36
-
-
Save JessicaWachtel/1357404219b0616f4fd689b8b18f8b22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as WasmModule from './pkg/index.js'; | |
| // Expose the function globally for the HTML button's onclick handler for simplicity | |
| window.doMath = async () => { | |
| // The Wasm module handles instantiation when first imported/awaited | |
| const { add, greet } = await WasmModule.instantiate(fetch('./pkg/release.wasm')); | |
| const num1 = parseInt(document.getElementById('num1').value); | |
| const num2 = parseInt(document.getElementById('num2').value); | |
| // Call the Wasm functions directly | |
| const sum = add(num1, num2); | |
| const message = greet("User"); | |
| document.getElementById('result').textContent = `${message} ${sum}`; | |
| console.log(`Wasm result: ${sum}`); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment