github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/tests/wasm/testdata/log.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "log" 6 "syscall/js" 7 ) 8 9 func main() { 10 11 // try various log and other output directly 12 log.Println("log 1") 13 log.Print("log 2") 14 log.Printf("log %d\n", 3) 15 println("println 4") 16 fmt.Println("fmt.Println 5") 17 log.Printf("log %s", "6") 18 19 // now set up some log output in a button click callback 20 js.Global(). 21 Get("document"). 22 Call("querySelector", "#main"). 23 Set("innerHTML", `<button id="testbtn">Test</button>`) 24 25 js.Global(). 26 Get("document"). 27 Call("querySelector", "#testbtn"). 28 Call("addEventListener", "click", 29 js.FuncOf(func(this js.Value, args []js.Value) interface{} { 30 println("in func 1") 31 log.Printf("in func 2") 32 return nil 33 })) 34 35 // click the button 36 js.Global(). 37 Get("document"). 38 Call("querySelector", "#testbtn"). 39 Call("click") 40 41 }