Skip to content

Instantly share code, notes, and snippets.

@JessicaWachtel
Created December 15, 2025 18:36
Show Gist options
  • Select an option

  • Save JessicaWachtel/1357404219b0616f4fd689b8b18f8b22 to your computer and use it in GitHub Desktop.

Select an option

Save JessicaWachtel/1357404219b0616f4fd689b8b18f8b22 to your computer and use it in GitHub Desktop.
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