github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/bench/wasmcall/main.go (about) 1 package main 2 3 import ( 4 "syscall/js" 5 ) 6 7 func main() { 8 js.Global().Set("add", js.FuncOf(func(this js.Value, args []js.Value) interface{} { 9 return Add(args[0].Float(), args[1].Float()) 10 })) 11 js.Global().Set("sub", js.FuncOf(func(this js.Value, args []js.Value) interface{} { 12 return Sub(args[0].Float(), args[1].Float()) 13 })) 14 select{} 15 } 16 17 //export add 18 func Add(a, b float64) float64 { 19 return a + b 20 } 21 22 //export sub 23 func Sub(a, b float64) float64 { 24 return a - b 25 }