diff --git a/lib/class_builder.js b/lib/class_builder.js index 660458a..8af2a73 100644 --- a/lib/class_builder.js +++ b/lib/class_builder.js @@ -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 ); } diff --git a/test/test-class_builder-static.js b/test/test-class_builder-static.js index 2b07a56..03f44d7 100644 --- a/test/test-class_builder-static.js +++ b/test/test-class_builder-static.js @@ -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" + ); +} )(); +