DEV Community

Cover image for :Goarch! WASM
Malik Benkirane
Malik Benkirane

Posted on

:Goarch! WASM

cover image source: egghead.io

The tools

Getting started

import syscall/js
Enter fullscreen mode Exit fullscreen mode
$ GOARCH=wasm GOOS=js go build ...
Enter fullscreen mode Exit fullscreen mode

Setting values

js.Global()
js.Global().Set(varname, js.ValueOf(x))
Enter fullscreen mode Exit fullscreen mode

Console logging

println()
Enter fullscreen mode Exit fullscreen mode

Expose **callbacks**

Js.Global().Set(ftname, js.NewCallback(f))
Enter fullscreen mode Exit fullscreen mode

Interoperability

func f(i []js.Value) {
  // f(a), i[0]=a
  // f(a,b), i[0]=a, i[1]=b
  // ...
}
Enter fullscreen mode Exit fullscreen mode

Illustrations

to be continued

Top comments (0)