1
0
Fork 0

Added access to parent prototype via parent property

closure/master
Mike Gerwitz 2010-11-10 22:54:24 -05:00
parent 607bbf7f4c
commit 0c963d1d00
2 changed files with 21 additions and 0 deletions

View File

@ -111,6 +111,9 @@ var extend = function()
// copy the given properties into the new prototype // copy the given properties into the new prototype
prop_copy( props, prototype ); prop_copy( props, prototype );
// reference to the parent prototype (for more experienced users)
prototype.parent = base.prototype;
// set up the new class // set up the new class
attach_extend( new_class ); attach_extend( new_class );
new_class.prototype = prototype; new_class.prototype = prototype;

View File

@ -59,6 +59,11 @@ var SubFoo = Foo.extend(
{ {
return this.__super( arg ); return this.__super( arg );
}, },
callParentAlt: function()
{
return this.parent.myMethod2.apply( this, arguments );
},
}); });
var foo = new Foo(), var foo = new Foo(),
@ -100,3 +105,16 @@ assert.equal(
"Arguments should be passed to super method via _super argument list" "Arguments should be passed to super method via _super argument list"
); );
assert.deepEqual(
SubFoo.prototype.parent,
Foo.prototype,
"Parent property should represent parent prototype"
);
sub_foo.callParentAlt( arg = 'moo' );
assert.equal(
sub_foo.method2Arg,
arg,
"The parent property may also be used to invoke parent methods"
);