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
prototype
object entirely, the originalconstructor
reference is removed with the originalprototype
object and is instead inherited from thenew A()
, etc.So, you'll have to reset the
constructor
after setting theprototype
: