Last active
October 20, 2021 05:24
-
-
Save ItalyPaleAle/4b83917d2ae561e23b9d071be710377f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (C) 2020 Alessandro Segala (ItalyPaleAle) | |
// License: MIT | |
package main | |
// Import the package to access the Wasm environment | |
import ( | |
"syscall/js" | |
) | |
// Main function: it sets up our Wasm application | |
func main() { | |
// Define the function "MyGoFunc" in the JavaScript scope | |
js.Global().Set("MyGoFunc", MyGoFunc()) | |
// Prevent the function from returning, which is required in a wasm module | |
select {} | |
} | |
// MyGoFunc returns a JavaScript function | |
func MyGoFunc() js.Func { | |
return js.FuncOf(func(this js.Value, args []js.Value) interface{} { | |
// Return a JS dictionary with two keys (of heterogeneous type) | |
return map[string]interface{}{ | |
"hello": "world", | |
"answer": 42, | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment