I have got this problem... B is a base class, and A is a derived class... Event though A is derived from B, various objects of A points to the same object of B.
I know i have assigned an object of B to the prototype of A to make A child of B.
But different objects of A, they should have different address space to hold the variables, right? Can you anyone correct this?
function B(){
this.obj = {};
}
function A(){
}
A.prototype = new B();
var a = new A();
var b = new A();
var c = new A();
console.log(a.obj == b.obj); //prints true
console.log(a.obj === b.obj); //prints true
a.obj.name = "stackoverflow";
console.log(b.obj.name); //prints stackoverflow
What change should I make in this code so that gives me following result.
a.obj === b.obj //must be false
a instanceof A; //must be true
a instanceof B; //must be true