Turns out this was simply a case of miss-typed code along with a
miss-understanding of how the class name gets determined. My code does in
fact now correctly reflect `instanceof Vector3` (I was accidentally testing
an object that really wasn't a Vector3). Now I'm just left with
understanding why the function name doesn't become the 'class name' when
printing the object (ie: [object Object] rather than [object Vector3]).
Cheers, Brett
On Monday, October 20, 2014 5:08:17 PM UTC-3, Brett Lawson wrote:
>
> I'm currently embedding v8 in an application. As part of this
> application, I need to instantiate 'Classes' that were defined in JS-land.
> Whenever I use ->NewInstance, the prototype chain does not get set
> properly, causing instanceof to fail (among other things, like the ToString
> showing 'Object' instead of 'Vector3').
>
> *Example C++-ish:*
> Local<Function> constructor = [...].Get("Vector3").As<Function>();
> Local<Object> newObject = constructor.NewInstance();
> [...].Set("someInstance", newObject);
>
> Example JS:
> Test.Vector3 = function Vector3() {
> this.x = 1337;
> }
> doCpp();
> console.log(someInstance instanceof Object);
> console.log(someInstance instanceof Test.Vector3);
> console.log(someInstance.x);
> console.log(someInstance);
>
> In this case, I get the following as output:
> true
> false
> 1337
> [object Object]
>
> When I expect to see:
> true
> true
> 1337
> [object Vector3]
>
> Cheers, Brett
>
--
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.