On Sat, Oct 3, 2009 at 4:03 AM, Tom Robinson <[email protected]> wrote:
>
> I have been unable to figure out how to call a function defined in
> JavaScript as a constructor, i.e. "new Foo()" instead of just "Foo()".
>
> Basically the equivalent of this: 
> http://developer.apple.com/mac/library/documentation/Carbon/Reference/WebKit_JavaScriptCore_Ref/JSObjectRef_h/index.html#/
> /apple_ref/c/func/JSObjectCallAsConstructor
>
> Is this possible in the V8 API? Can I somehow instantiate an object of
> the right type based on the constructor, then pass it to Call(recv,
> argc, argv) as the "recv" arg?
>

Something like this (not tested)

  Local<Value> foo_v = global->Get(String::New("Foo"));
  assert(foo_v->IsFunction());
  Local<Function> foo = Local<Function>::Cast(foo_v);
  Local<Object> foo_instance = foo->NewInstance(); // or NewInstance(argc, argv)

--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to