diff --git a/lib/ClassBuilder.js b/lib/ClassBuilder.js index f8335e7..7eadf9a 100644 --- a/lib/ClassBuilder.js +++ b/lib/ClassBuilder.js @@ -388,11 +388,11 @@ exports.prototype.build = function extend( _, __ ) prototype, prop_init, members, new_class, this._classId ); - new_class.prototype = prototype; - new_class.constructor = new_class; - new_class.___$$props$$ = prop_init; - new_class.___$$methods$$ = members; - new_class.___$$sinit$$ = staticInit; + new_class.prototype = prototype; + new_class.prototype.constructor = new_class; + new_class.___$$props$$ = prop_init; + new_class.___$$methods$$ = members; + new_class.___$$sinit$$ = staticInit; attachFlags( new_class, props ); @@ -692,6 +692,7 @@ exports.prototype.createConcreteCtor = function( cname, members ) ) ; } + }; // provide a more intuitive string representation diff --git a/test/test-class-constructor.js b/test/test-class-constructor.js index 89ab46a..87d717d 100644 --- a/test/test-class-constructor.js +++ b/test/test-class-constructor.js @@ -167,3 +167,20 @@ assert.ok( }, TypeError, "Constructor cannot be private" ); } )(); + +/** + * When a constructor is instantiated, the instance's 'constructor' property is + * set to the constructor that was used to instantiate it. The same should be + * true for class instances. + * + * This will also be important for reflection. + */ +( function testConsructorPropertyIsProperlySetToClass() +{ + var Foo = Class( {} ); + + assert.ok( Foo().constructor === Foo, + "Instance constructor should be set to class" + ); +} )(); +