var print = function(text){
document.write(text);
document.write("</br>");
}
var A = function(){
}
A.prototype.name="A";
var B = function(){
}
B.prototype = new A();
B.prototype.name="B";
var C = function(){
}
C.prototype = new B();
C.prototype.name="C";
obj = new C();
print(obj.name);
print(obj.constructor.prototype.name);
print(obj.constructor == A);
This code gives next output:
C
A
true
Why obj.constructor here is A and not C ?
As seen in this code sample, you have to manually reset the
.constructorproperty when using inheritance, or your constructor is being overridden when you callnew A()ornew B():Here is a working sample: http://jsfiddle.net/93Msp/.
Hope this helps!