Browse Source

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

Dmitry Panov 3 years ago
parent
commit
cc28e89bfc
1 changed files with 6 additions and 1 deletions
  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
     // 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
     // This way it is possible to return a Go struct or a map converted
     // into goja.Value using ToValue(), however in this case
     // 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
     return nil
  }
  }