Inherited static members are no longer copied by reference
- Sharing values with supertype = badclosure/master
parent
604e03fa55
commit
aead20290c
|
@ -575,8 +575,9 @@ function attachStatic( ctor, members, base )
|
|||
baseinit( ctor );
|
||||
}
|
||||
|
||||
// copy over public static members
|
||||
util.copyTo( ctor, members[ 'public' ] );
|
||||
// copy over public static members (deep copy; we don't want subtypes to
|
||||
// share references with their parents)
|
||||
util.copyTo( ctor, members[ 'public' ], true );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -286,3 +286,29 @@ var common = require( './common' ),
|
|||
}
|
||||
} )();
|
||||
|
||||
|
||||
/**
|
||||
* Each class should have its own set of static values. That is, a subtype
|
||||
* should not share references with its parent.
|
||||
*/
|
||||
( function testInheritedPublicStaticPropertiesAreClones()
|
||||
{
|
||||
var val = [ 1, 2, 3 ],
|
||||
Foo = builder.build(
|
||||
{
|
||||
'public static bar': val,
|
||||
} ),
|
||||
SubFoo = builder.build( Foo, {} )
|
||||
;
|
||||
|
||||
// the values should certainly be equal...
|
||||
assert.deepEqual( SubFoo.bar, Foo.bar,
|
||||
"Inherited static properties should be equal by value"
|
||||
);
|
||||
|
||||
// ...but they should not be the same object
|
||||
assert.ok( SubFoo.bar !== Foo.bar,
|
||||
"Inherited static propertis should not be the same object"
|
||||
);
|
||||
} )();
|
||||
|
||||
|
|
Loading…
Reference in New Issue