github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/examples/wasm/export/wasm.go (about) 1 package main 2 3 import ( 4 "strconv" 5 "syscall/js" 6 ) 7 8 func main() { 9 } 10 11 //export add 12 func add(a, b int) int { 13 return a + b 14 } 15 16 //export update 17 func update() { 18 document := js.Global().Get("document") 19 aStr := document.Call("getElementById", "a").Get("value").String() 20 bStr := document.Call("getElementById", "b").Get("value").String() 21 a, _ := strconv.Atoi(aStr) 22 b, _ := strconv.Atoi(bStr) 23 result := add(a, b) 24 document.Call("getElementById", "result").Set("value", result) 25 }