-
I'd like to create an object (here a fictional “document”) and call methods on it. I can set a function like How do I implement the package main
import (
"fmt"
"os"
"github.com/dop251/goja"
)
type document struct{}
func newDocument() *document {
return &document{}
}
func (d *document) DoSomething() {
}
func main() {
runtime := goja.New()
gjNewDoc := func(call goja.FunctionCall) goja.Value {
return runtime.ToValue(newDocument())
}
runtime.Set("newdoc", gjNewDoc)
v, err := runtime.RunString(`
var d = newdoc();
// d.dosomething();
`)
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
fmt.Println(v)
} |
Beta Was this translation helpful? Give feedback.
Answered by
dop251
Nov 2, 2022
Replies: 1 comment 1 reply
-
Methods are already exposed, as long as they are exported, so in your example |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
pgundlach
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Methods are already exposed, as long as they are exported, so in your example
d.DoSomething()
would work.