紧急情况:syscall / js:Value.Call:属性_makeFuncWrapper不是函数,未定义

时间:2019-07-22 22:40:22

标签: javascript go webassembly

我正在尝试将html按钮编译为webassembly事件监听器。 我包括了js库: wasm_exec.js

package main

import (
    dom "github.com/siongui/godom/wasm"
    "syscall/js"
)

func main() {

    // Create a channel that doesn't let our Go program exit
    c := make(chan bool)

    app := dom.Document.GetElementById("app")     
    button := dom.Document.CreateElement("button")
    text := dom.Document.CreateElement("span")

    // Set button text
    button.Set("textContent", "Click on me")

    // Callback for click event
    var cb js.Func
    cb = js.FuncOf(func(this js.Value, args []js.Value) interface{} {
        text.Set("textContent", "Button was clicked")
        return nil
    })

    js.Global().Get("body").Call("getElementById", "test01").Call("addEventListener", "click", cb)

    // Add event listener to a button
    button.Call("addEventListener", "click", cb)

    app.Call("appendChild", text)
    app.Call("appendChild", button)

    <-c

}

此go代码会编译。 但是wasm在执行过程中中断了,我在浏览器控制台中得到的只是:

panic: syscall/js: Value.Call: property _makeFuncWrapper is not a function, got undefined wasm_exec.js:41:14
wasm_exec.js:41:14
goroutine 1 [running]: wasm_exec.js:41:14
syscall/js.Value.Call(0x7ff8000000000007, 0x207fa, 0x10, 0xc036ed0, 0x1, 0x1, 0x10) wasm_exec.js:41:14
    /home/kamil/utils/go/src/syscall/js/js.go:299 +0x87 wasm_exec.js:41:14
syscall/js.FuncOf(0xc01e030, 0xc01e030, 0xb) wasm_exec.js:41:14
    /home/kamil/utils/go/src/syscall/js/func.go:46 +0xa wasm_exec.js:41:14
main.main() wasm_exec.js:41:14
    /home/kamil/projects/go-wasm/index.go:23 +0x14 wasm_exec.js:41:14
exit code: 2

有什么想法我在做什么错吗?

0 个答案:

没有答案