We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
从发展历史可以总结技术发展规律,如何从一个个人项目到W3C标准
为什么把worker拿出来,因为两者可以搭配使用
// js胶水代码 cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" .
// html模版代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <div id="root"></div> </body> <script src="wasm_exec.js"></script> <script> const go = new Go(); WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject) .then((result) =>{ go.run(result.instance) }); </script> </html>
package main import ( "fmt" "syscall/js" "time" ) // js可以调用的函数 func forJsFunc(this js.Value, args []js.Value) any { // duration := int(js.Value(args[0]).Int()) duration := args[0].Int() var cb = args[len(args)-1] go func() { // time.Sleep(time.Second * duration) time.Sleep(time.Duration(duration) * time.Second) str := fmt.Sprintf("it's %d second", duration) cb.Invoke(js.ValueOf(str)) }() return nil } func main() { done := make(chan int, 0) // js的golbal var jsGlobal = js.Global() // Set、Get对象等 var document = jsGlobal.Get("document") var root = document.Call("getElementById", "root") root.Set("innerHTML", js.ValueOf("hello world!")) var alert = jsGlobal.Get("alert") // 执行 alert.Invoke("alert") // 设置js的全局函数 jsGlobal.Set("wamsFunc", js.FuncOf(forJsFunc)) <-done } // 编译 GOARCH=wasm GOOS=js go build -o test.wasm main.go
Golang syscall/js 文档
The text was updated successfully, but these errors were encountered:
No branches or pull requests
什么是WebAssembly
发展历史
从性能进一步探索前端方案:WebAssembly、Worker、JavaScript对比
eg用golang写wasm
Golang syscall/js 文档
The text was updated successfully, but these errors were encountered: