I've finally got this working by using the internal field on
args.This() instead.

But a new problem arose. If the user should forget to call the Base
constructor in the Derived constructor, my native Base constructor is
never called for the newly created Derived instance!

Is there a callback for "new", when an instance of the prototype is
created?

If I do:

function Array2 () {}
Array2.prototype = new Array;
Array2.prototype.constructor = Array2;

The Array2 is correctly initialized, without having to
Array.call(this) in the constructor.


On Tue, Mar 16, 2010 at 7:07 AM, Anton Muhin <ant...@google.com>
wrote:
> That's expected behaviour.  Roughly: for native methods to operate
> properly they assume holder naturally holds native data.  But you
> always have This() at your disposal to either find Derived or just
> read properties in normal JS way.
>
> hth and yours,
> anton.
>
> On Tue, Mar 16, 2010 at 1:35 AM, Henrik Lindqvist
> <henrik.lindqv...@gmail.com> wrote:
>> To my knowledge, inheritance in JavaScript should be written:
>
>> function Base () {
>>  // Initialize Base
>> }
>
>> function Derived () {
>>  Base.call(this); // call Base constructor and initialize Base
>> "parts"
>>  // Initialize Derived
>> }
>> Derived.prototype = new Base;
>> Derived.prototype.constructor = Derived;
>
>> How do I allow for this to work if Base is a wrapped native instance
>> with an internal field, and Derived is a script only object?
>
>> When using Signature, args.Holder() seems to contain the prototype
>> instance of Base, not the inherited script Derived instance.


-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users

Reply via email to