github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/tests/wasm/testdata/event.go (about) 1 package main 2 3 import "syscall/js" 4 5 func main() { 6 7 ch := make(chan bool, 1) 8 9 println("1") 10 11 js.Global(). 12 Get("document"). 13 Call("querySelector", "#main"). 14 Set("innerHTML", `<button id="testbtn">Test</button>`) 15 16 js.Global(). 17 Get("document"). 18 Call("querySelector", "#testbtn"). 19 Call("addEventListener", "click", 20 js.FuncOf(func(this js.Value, args []js.Value) interface{} { 21 println("2") 22 ch <- true 23 println("3") 24 return nil 25 })) 26 27 println("4") 28 v := <-ch 29 println(v) 30 31 }