On Tue, Mar 31, 2009 at 9:13 AM, Stephan Beal <[email protected]> wrote:
>
> On Tue, Mar 31, 2009 at 4:29 PM, Louis Santillan <[email protected]> wrote:
>>   ChildClass._superConstructor_ = ParentClass;
>>   ChildClass._superClass_ = ParentClass.prototype;

Need to be careful here.  The intent is to modify the static class
members here.  For the reason why, see below.

>
> i wasn't able to get that to work:
>
> subclass.js:24: TypeError: Cannot call method 'call' of undefined
>  this._superConstructor_.call( this );

...Because I made a typo.  For clarity, the _superConstructor_.call()
is referenced via SuperType._superConstructor_.call( this ).  This
allows for the selection of which super constructor (really any member
method) you would like to call.  So, if you have an inheritance chain
like Person->Employee->Manager, from Manager's constructor you can
call Employee._superConstructor_, or Person._superConstructor_, or
Person.setPhoneNumber or Employee.setPhoneNumber.  A nice feature that
call/apply & prototypal inheritance lets you exploit.


>
> but this change works for me:
>
>  ChildClass.prototype._superConstructor_ = ParentClass;
>  ChildClass.prototype._superClass_ = ParentClass.prototype;
>
> note the insertion of ".prototype".
>
>> Object._extends_( MySubType, MyType );
>
> Then i hacked it a bit...
>
> Since MySubType already subclasses Object, we can change:
>
> Object.prototype._extends_ = function( ChildClass, ParentClass )
> {
>    if( 1 == arguments.length )
>    {
>        return this._extends_(this,ChildClass);
>    }
> ... same as before ...
> }
>
> And:
>
>> Object._extends_( MySubType, MyType );
>
> becomes:
>
> MySubType._extends_(MyType);
>
> otherwise _extends_ might as well be a non-member function.
>
> Thanks for that tip! This will be useful!

I don't remember at the moment, but this might breakdown for some
patterns of inheritance.  I need re-read this article
(http://webreflection.blogspot.com/2007/07/javascript-prototypal-inheritance-using.html)
to explain why (at one time, I had made the same changes and it didn't
work for me and I forget which test failed).

-Louis

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

Reply via email to