Overridden methods now property return instance when returning 'this'
- There may be a cleaner way to do this. This is a quick fix.closure/master
parent
84363aca45
commit
e0fb37daa0
|
@ -319,12 +319,22 @@ function overrideMethod( super_method, new_method, instCallback )
|
|||
{
|
||||
override = function()
|
||||
{
|
||||
var context = instCallback( this ) || this,
|
||||
retval = undefined
|
||||
;
|
||||
|
||||
// the _super property will contain the parent method
|
||||
this.__super = super_method;
|
||||
|
||||
var retval = new_method.apply(
|
||||
( instCallback( this ) || this ), arguments
|
||||
);
|
||||
retval = new_method.apply( context, arguments );
|
||||
|
||||
// if the value returned from the method was the context that we
|
||||
// passed in, return the actual instance (to ensure we do not break
|
||||
// encapsulation)
|
||||
if ( retval === context )
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
return retval;
|
||||
};
|
||||
|
|
|
@ -67,13 +67,25 @@ var common = require( './common' ),
|
|||
{
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
'public getSelfOverride': function()
|
||||
{
|
||||
// override me
|
||||
},
|
||||
}),
|
||||
|
||||
// instance of Foo
|
||||
foo = Foo(),
|
||||
|
||||
// subtype
|
||||
SubFoo = Foo.extend( {} ),
|
||||
SubFoo = Foo.extend({
|
||||
'public getSelfOverride': function()
|
||||
{
|
||||
// return this from overridden method
|
||||
return this;
|
||||
},
|
||||
}),
|
||||
sub_foo = SubFoo()
|
||||
;
|
||||
|
||||
|
@ -341,5 +353,12 @@ var common = require( './common' ),
|
|||
sub_foo,
|
||||
"Returning 'this' from a super method should return the subtype"
|
||||
);
|
||||
|
||||
// finally, overridden methods should still return the instance
|
||||
assert.deepEqual(
|
||||
sub_foo.getSelfOverride(),
|
||||
sub_foo,
|
||||
"Returning 'this' from a overridden method should return the subtype"
|
||||
);
|
||||
} )();
|
||||
|
||||
|
|
Loading…
Reference in New Issue