added test for wasm log output

callback case for log test
This commit is contained in:
Brad Peabody
2020-05-23 11:35:37 -07:00
committed by Ron Evans
parent 67ac4fdd8e
commit 4918395f88
3 changed files with 101 additions and 4 deletions
+41
View File
@@ -0,0 +1,41 @@
package main
import (
"fmt"
"log"
"syscall/js"
)
func main() {
// try various log and other output directly
log.Println("log 1")
log.Print("log 2")
log.Printf("log %d\n", 3)
println("println 4")
fmt.Println("fmt.Println 5")
log.Printf("log %s", "6")
// now set up some log output in a button click callback
js.Global().
Get("document").
Call("querySelector", "#main").
Set("innerHTML", `<button id="testbtn">Test</button>`)
js.Global().
Get("document").
Call("querySelector", "#testbtn").
Call("addEventListener", "click",
js.FuncOf(func(this js.Value, args []js.Value) interface{} {
println("in func 1")
log.Printf("in func 2")
return nil
}))
// click the button
js.Global().
Get("document").
Call("querySelector", "#testbtn").
Call("click")
}