Skip to content

Instantly share code, notes, and snippets.

@KrzysztofZawisla
Created August 30, 2019 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KrzysztofZawisla/d96c47f9d8bc166437e3c09cb6070896 to your computer and use it in GitHub Desktop.
Save KrzysztofZawisla/d96c47f9d8bc166437e3c09cb6070896 to your computer and use it in GitHub Desktop.
func WasmQueryOn(this js.Value, args []js.Value) interface{} {
if len(args) > 1 {
selector := args[0]
function := args[1]
if function.Type() == js.TypeFunction && selector.Type() == js.TypeString {
jsSelector := js.Global().Get("String").New(selector)
firstLetter := jsSelector.Call("substr", 0, 1)
firstLetterUpperCase := js.Global().Get("String").New(firstLetter).Call("toUpperCase")
restOfWord := jsSelector.Call("substr", 1, selector.Length()-1)
value := "on" + firstLetterUpperCase.String() + restOfWord.String()
this.Call("addEventListener", value, function)
}
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment