One more try:

In my constructor function foo:

static void
foo(const v8::FunctionCallbackInfo<v8::Value>& args)
{
  v8::Isolate* isolate = args.GetIsolate();
  v8::HandleScope handleScope(isolate);
  args.GetReturnValue().Set(
    v8::Local<v8::Function>::Cast(args.This())->New(isolate,bar));
}

> var f = new Foo();
> f instanceof Foo;
false

Now if I change New to NewInstance, I get a crash from V8.  I don't see why 
an instance new'ed from the function still isn't "instanceof" the function.

Jane


On Wednesday, October 8, 2014 2:26:02 PM UTC-7, Ben Noordhuis wrote:
>
> On Wed, Oct 8, 2014 at 10:02 PM, Jane Chen <[email protected] 
> <javascript:>> wrote: 
> > I was able to get instanceof returning true following your tips. 
>  Thanks. 
> > But it seems to me this design assumes that there is only a singleton 
> > Function we are operating on as I'm always interacting with This, which 
> is 
> > the function returned from FunctionTemplate.GetFunction(). 
> > 
> > If I want to dynamically create embedded objects from FunctionTemplates, 
> is 
> > there a way to keep them "instanceof" of a certain class? 
>
> `o instanceof F` is more or less equivalent to recursively checking if 
> `o.__proto__.constructor === F`.  That is, you can make objects pass 
> the instanceof test by making their constructors inherit from one 
> another.  For example: 
>
>   function A() {} 
>   function B() {} 
>   B.prototype = Object.create(A.prototype); 
>   (new B) instanceof A;  // true 
>
> You can accomplish the same thing with the C++ API in a number of 
> ways.  In your case, just FunctionTemplate::Inherit() might be enough. 
>

-- 
-- 
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.

Reply via email to