A namespace is a named JavaScript scope or object for organizing functions exposed by Go WebAssembly. Registering on js.Global() makes a function available everywhere; assigning it to a specific object keeps the API narrower. section 12.2.2
Choose the exposure scope according to application size:
- Use the global namespace for a small application, calling generate(). section 12.2.2
- Create a JavaScript object for a specific namespace, expose it as multiplyApp, and call multiplyApp.generate(). section 12.2.2
Expose a function under a namespace
multiply := js.Global().Get("Object").New()\nmultiply.Set("generate", js.FuncOf(m.generate))\njs.Global().Set("multiplyApp", multiply)\n\nThe browser can then invoke multiplyApp.generate(). section 12.2.2
Listing 12.12 main.go : Exposing a function in a specific namespace
multiply := js.Global().Get("Object").New() #1
multiply.Set("generate", js.FuncOf(m.generate)) #2
js.Global().Set("multiplyApp", multiply) #3
Inspect the complete object-creation and function-registration pattern. section 12.2.2



















