1
0
Fork 0

Inherited static members are no longer copied by reference

- Sharing values with supertype = bad
closure/master
Mike Gerwitz 2011-04-05 23:47:44 -04:00
parent 604e03fa55
commit aead20290c
2 changed files with 29 additions and 2 deletions

View File

@ -575,8 +575,9 @@ function attachStatic( ctor, members, base )
baseinit( ctor ); baseinit( ctor );
} }
// copy over public static members // copy over public static members (deep copy; we don't want subtypes to
util.copyTo( ctor, members[ 'public' ] ); // share references with their parents)
util.copyTo( ctor, members[ 'public' ], true );
} }

View File

@ -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"
);
} )();