On Mon, Oct 6, 2008 at 4:40 PM, Ben Nolan <[EMAIL PROTECTED]> wrote:
>
> Hi all,
>
> What is the correct way of creating an instance of a javascript class
> from within C++, so that methods that are added to the
> class .prototype in javascript are available on the new instance?
>
> eg:
>
> javascript:
>
> Vector.prototype.inspect = function(){
> return "x=" + this.x;
> }
>
> c++
>
> template_ = ObjectTemplate::New();
> template_->SetInternalFieldCount(1);
> template_->SetAccessor(String::New("x"), getX, setX);
You can create a function template first, and it has a prototype
template, set getX, setX on the prototype template.
>From function template, you can get instance template which is the
object template you need.
>
> MyVector vector;
> Local<Object> instance = template_->NewInstance();
> instance->SetInternalField(0, External::New(vector));
>
> I can't work out how it should inherit from the Vector prototype
> chain... Am I missing something?
>
> Ben
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---