Added access to parent prototype via parent property
parent
607bbf7f4c
commit
0c963d1d00
|
@ -111,6 +111,9 @@ var extend = function()
|
|||
// copy the given properties into the new prototype
|
||||
prop_copy( props, prototype );
|
||||
|
||||
// reference to the parent prototype (for more experienced users)
|
||||
prototype.parent = base.prototype;
|
||||
|
||||
// set up the new class
|
||||
attach_extend( new_class );
|
||||
new_class.prototype = prototype;
|
||||
|
|
|
@ -59,6 +59,11 @@ var SubFoo = Foo.extend(
|
|||
{
|
||||
return this.__super( arg );
|
||||
},
|
||||
|
||||
callParentAlt: function()
|
||||
{
|
||||
return this.parent.myMethod2.apply( this, arguments );
|
||||
},
|
||||
});
|
||||
|
||||
var foo = new Foo(),
|
||||
|
@ -100,3 +105,16 @@ assert.equal(
|
|||
"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"
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue