javascript - shallow copy issue
<p>I just tried something simple in javascript</p>

<pre><code>name = 'velu' 
fname = name
name = 'valu'
console.log(fname) // would still print as velu...
</code></pre>

<p>how do you handle situation where you generated objects prototype is changed and the generated object still has a copy of the old object..</p>

<p>Here is the situation ...</p>

<pre><code>function Cat(name){  
this.name = name  
}
var garfield = new Cat('Garfield')
Cat.prototype.greet = function(){
console.log('Meow, I am ' + this.name)
}
function Animal(){}
Cat.prototype = new Animal
Cat.prototype.constructor = Cat 
Animal.prototype.breed = function(){
console.log('Making a new animal!')
return new this.constructor()
}
 var kitty = garfield.breed() // this will not work as it garfield still is pointing to the old prototype object of Cat ...
</code></pre>

<p>thanks</p>
