I am confused with the following prototype behavior in javascript.
function A(){
};
A.prototype.toString = function(){
console.log('first');
}
var a = new A(), b;
A.prototype = {
toString:function(){
console.log('second');
}
}
b = new A();
a.toString();
//outputs : first
b.toString();
//outputs : second
Why does a.toString still prints "frist" when compared to b.toString which prints "second". can anyone please explain what i am missing here.
var a = new A(), b
? – elclanrs Jun 18 '13 at 21:58b
as var. It's all good. – elclanrs Jun 18 '13 at 22:05