Explorar o código

Added a note about setting prototype on a custom constructor return value. See #340

Dmitry Panov %!s(int64=3) %!d(string=hai) anos
pai
achega
cc28e89bfc
Modificáronse 1 ficheiros con 6 adicións e 1 borrados
  1. 6 1
      runtime.go

+ 6 - 1
runtime.go

@@ -1462,7 +1462,12 @@ operator:
     // If return value is a non-nil *Object, it will be used instead of call.This
     // This way it is possible to return a Go struct or a map converted
     // into goja.Value using ToValue(), however in this case
-    // instanceof will not work as expected.
+    // instanceof will not work as expected, unless you set the prototype:
+    //
+    // instance := &myCustomStruct{}
+    // instanceValue := vm.ToValue(instance).(*Object)
+    // instanceValue.SetPrototype(call.This.Prototype())
+    // return instanceValue
     return nil
  }