just ran into this little confusion while playing around with javascript inheritance.
function A() {}
function B() {}
B.prototype = new A();
function C() {}
C.prototype = new B();
var x = new C();
x.construction // -> returns A in chrome console.
I was expecting x.constructor to be C (or even B maybe) but not all the way to A (why even stop at A and not show Object then)
When you replace the
prototypeobject entirely, the originalconstructorreference is removed with the originalprototypeobject and is instead inherited from thenew A(), etc.So, you'll have to reset the
constructorafter setting theprototype: