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

Function ExampleAssertConstructor

func_test.go:136–158  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

134}
135
136func ExampleAssertConstructor() {
137 vm := New()
138 res, err := vm.RunString(`
139 (class C {
140 constructor(x) {
141 this.x = x;
142 }
143 })
144 `)
145 if err != nil {
146 panic(err)
147 }
148 if ctor, ok := AssertConstructor(res); ok {
149 obj, err := ctor(nil, vm.ToValue("Test"))
150 if err != nil {
151 panic(err)
152 }
153 fmt.Print(obj.Get("x"))
154 } else {
155 panic("Not a constructor")
156 }
157 // Output: Test
158}
159
160type testAsyncCtx struct {
161 group string

Callers

nothing calls this directly

Calls 5

NewFunction · 0.85
AssertConstructorFunction · 0.85
RunStringMethod · 0.80
ToValueMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…