MCPcopy Create free account
hub / github.com/dop251/goja / ExampleRuntime_ExportTo_funcVariadic

Function ExampleRuntime_ExportTo_funcVariadic

runtime_test.go:943–962  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

941}
942
943func ExampleRuntime_ExportTo_funcVariadic() {
944 const SCRIPT = `
945 function f(...args) {
946 return args.join("#");
947 }
948 `
949 vm := New()
950 _, err := vm.RunString(SCRIPT)
951 if err != nil {
952 panic(err)
953 }
954
955 var fn func(args ...interface{}) string
956 err = vm.ExportTo(vm.Get("f"), &fn)
957 if err != nil {
958 panic(err)
959 }
960 fmt.Println(fn("a", "b", 42))
961 // Output: a#b#42
962}
963
964func TestRuntime_ExportTo_funcVariadic(t *testing.T) {
965 const SCRIPT = `

Callers

nothing calls this directly

Calls 4

NewFunction · 0.85
RunStringMethod · 0.80
ExportToMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…