go: github.com/shurcooL/go/gopherjs_http/jsutil Index | Files

package jsutil

import "github.com/shurcooL/go/gopherjs_http/jsutil"

Package jsutil provides utility functions for interacting with native JavaScript APIs.


Package Files


func Wrap Uses

func Wrap(fn interface{}) func(...*js.Object)

Wrap returns a wrapper func that handles the conversion from native JavaScript *js.Object parameters to the following types.

It supports *js.Object (left unmodified), dom.Document, dom.Element, dom.Event, dom.HTMLElement, dom.Node. It has to be one of those types exactly; it can't be another type that implements the interface like *dom.BasicElement.

For other types, the input is assumed to be a JSON string which is then unmarshalled into that type.

Here is example usage:

<span onclick="Handler(event, this, {{.SomeStruct | json}});">Example</span>

func Handler(event dom.Event, htmlElement dom.HTMLElement, data someStruct) {
	data.Foo = ... // Use event, htmlElement, data.

func main() {
	js.Global.Set("Handler", jsutil.Wrap(Handler))

Package jsutil imports 4 packages (graph) and is imported by 4 packages. Updated 2016-07-15. Refresh now. Tools for package owners.