github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/syscall/js/js_test.go (about) 1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build js && wasm 6 7 // To run these tests: 8 // 9 // - Install Node 10 // - Add /path/to/go/misc/wasm to your $PATH (so that "go test" can find 11 // "go_js_wasm_exec"). 12 // - GOOS=js GOARCH=wasm go test 13 // 14 // See -exec in "go help test", and "go help run" for details. 15 16 package js_test 17 18 import ( 19 "github.com/shogo82148/std/fmt" 20 "github.com/shogo82148/std/syscall/js" 21 ) 22 23 func ExampleFuncOf() { 24 var cb js.Func 25 cb = js.FuncOf(func(this js.Value, args []js.Value) any { 26 fmt.Println("button clicked") 27 cb.Release() // release the function if the button will not be clicked again 28 return nil 29 }) 30 js.Global().Get("document").Call("getElementById", "myButton").Call("addEventListener", "click", cb) 31 }