On Tue, Mar 31, 2009 at 6:56 PM, Louis Santillan <[email protected]> wrote:
> ...Because I made a typo.  For clarity, the _superConstructor_.call()
> is referenced via SuperType._superConstructor_.call( this ).  This

Aha. Okay, for clarity, here's what i've got now (which seems to work):

Object.prototype._extends_ = function( ChildClass, ParentClass )
{
    if( 1 == arguments.length )
    {
        ParentClass = ChildClass;
        ChildClass = this;
    }
    function TempClass() {}
    TempClass.prototype = ParentClass.prototype;

    ChildClass.prototype = new TempClass();
    ChildClass.prototype.constructor = ChildClass;
    ChildClass.prototype._superConstructor_ = ParentClass;
    ChildClass.prototype._superClass_ = ParentClass.prototype;
}
Object.prototype._extends_ = function( ChildClass, ParentClass )
{
  function TempClass() {}
  TempClass.prototype = ParentClass.prototype;

  ChildClass.prototype = new TempClass();
  ChildClass.prototype.constructor = ChildClass;
  ChildClass._superConstructor_ = ParentClass;
  ChildClass._superClass_ = ParentClass.prototype;
};

var MyType = function()
{
    var av = Array.prototype.slice.apply(arguments,[0]);
    print("new MyType(",av.join(','),')');
  this.prop1 = 1;
};

var MySubType = function()
{
  var av = Array.prototype.slice.apply(arguments,[0]);
  MySubType._superConstructor_.call( this, av );
  print("new MySubType(",av.join(','),')');
  this.prop2 = 2;
};


Object._extends_( MySubType, MyType );

var x = new MySubType(7,3,11);

print( x.prop1 + ":" + x.prop2 );
print( x instanceof MyType );


Output:

new MyType( 7,3,11 )
new MySubType( 7,3,11 )
1:2
true


:-?

-- 
----- stephan beal
http://wanderinghorse.net/home/stephan/

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

Reply via email to