Make DOM Manipulation in Go as similar to JavaScript as possible via WebAssembly. For DOM Manipulation via GopherJS, visit root directory.
- Ubuntu 18.04
- Go (1.11 or later)
Table of Content
$ GOARCH=wasm GOOS=js go get -u github.com/siongui/godom/wasm
Why not use syscall/js directly?
Because the code written directly using syscall/js without any wrapper is really ugly. For example, if you want to getElementById, you need to write:
import (
"syscall/js"
)
foo := js.Global().Get("document").Call("getElementById", "foo")
With godom, you write:
import (
. "github.com/siongui/godom/wasm"
)
foo := Document.GetElementById("foo")
which looks like JavaScript and more readable.
godom is only a wrapper for syscall/js package. If something is not implemented, you can still use methods in syscall/js to call or get the method/property you need. For example, if the Play() method of the audio element is not implemented, you can use syscall/js Call method to call play method directly:
import (
. "github.com/siongui/godom/wasm"
)
a := Document.GetElementById("foo")
a.Call("play")
- Frontend Programming in Go: If you have no experience of Go WebAssembly before, read this.
[1] | WebAssembly · golang/go Wiki · GitHub |