WebAssembley compiling error

i’m learning go wasm, I came a cross
it’s out dated for go version 1.12.3 darwin/amd64
I found out js.NewCallback() no longer available.
New function call js.FuncOf() it’s very hard for me to figure out.
Can any one kindly help.

Error message with js.NewCallback()


./main.go:21:25: undefined: js.NewCallback

Error message with js.FuncOf()


./main.go:21:34: cannot use add (type func([]js.Value)) as type func(js.Value, []js.Value) interface {} in argument to js.FuncOf

this is my main.go
package main

import (

func add(i []js.Value) {
value1 := js.Global().Get(“document”).Call(“getElementById”, i[0].String()).Get(“value”).String()
value2 := js.Global().Get(“document”).Call(“getElementById”, i[1].String()).Get(“value”).String()

int1, _ := strconv.Atoi(value1)
int2, _ := strconv.Atoi(value2)

js.Global().Get("document").Call("getElementById", i[2].String()).Set("value", int1+int2)

//c <- true

func registerCallbacks() {
js.Global().Set(“add”, js.FuncOf(add))

func main() {
c := make(chan struct{}, 0)

println("WASM Go Initialized")
// register functions



I am maintaining examples of Go WebAssembly here:

Very simple: https://github.com/Yaoir/ClockExample-Go-WebAssembly
More complicated: https://github.com/Yaoir/VideoPoker-Go-WebAssembly

They are both updated to work with Go version 1.12.

I hope that helps.

thank you sir
I will look in to

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.