js.Func is the wrapper used to expose a Go function to JavaScript through the WebAssembly interoperability API. Create it with js.FuncOf rather than constructing it manually, then register it under a JavaScript name with Set. section 12.2.2
Account for the callback contract and its runtime behavior:
- Release functions when appropriate, because calling FuncOf too many times can leak resources. section 12.2.2
- Avoid returning errors directly: the js package turns callback errors into a panic. section 12.2.2
Expose a generate callback
Register a method globally with js.Global().Set("generate", js.FuncOf(m.generate)), then call it from HTML with generate() or a button’s onclick handler.
