Static property setter now returns calling class
parent
e3c526b89d
commit
7e53df0e84
|
@ -622,12 +622,17 @@ function attachStatic( ctor, members, base, inheriting )
|
|||
// failing to set perfectly legal values
|
||||
var has = Object.prototype.hasOwnProperty.call(
|
||||
props[ 'public' ], prop
|
||||
);
|
||||
),
|
||||
|
||||
// Determine if we were invoked in the context of a class. If
|
||||
// so, use that. Otherwise, use ourself.
|
||||
context = ( this.___$$sprops$$ ) ? this : ctor
|
||||
;
|
||||
|
||||
// if we don't own the property, let the parent(s) handle it
|
||||
if ( !has )
|
||||
{
|
||||
return base.$.apply( this, arguments );
|
||||
return base.$.apply( context, arguments );
|
||||
}
|
||||
|
||||
// if a value was provided, this method should be treated as a
|
||||
|
@ -635,7 +640,7 @@ function attachStatic( ctor, members, base, inheriting )
|
|||
if ( val )
|
||||
{
|
||||
props[ 'public' ][ prop ] = val;
|
||||
return;
|
||||
return context;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -370,3 +370,29 @@ var common = require( './common' ),
|
|||
);
|
||||
} )();
|
||||
|
||||
|
||||
/**
|
||||
* Ensure that the proper context is returned by static property setters. It
|
||||
* should return the calling class, regardless of whether or not it owns the
|
||||
* property being requested.
|
||||
*/
|
||||
( function testStaticPropertySettersReturnProperContext()
|
||||
{
|
||||
var Foo = builder.build(
|
||||
{
|
||||
'public static foo': '',
|
||||
} ),
|
||||
|
||||
SubFoo = builder.build( Foo, {} )
|
||||
;
|
||||
|
||||
assert.ok( Foo.$( 'foo', 'val' ) === Foo,
|
||||
"Static property setter returns self"
|
||||
);
|
||||
|
||||
assert.ok( SubFoo.$( 'foo', 'val' ) === SubFoo,
|
||||
"Static property setter returns calling class, even if property is " +
|
||||
"owned by a supertype"
|
||||
);
|
||||
} )();
|
||||
|
||||
|
|
Loading…
Reference in New Issue