I am learning how JS prototype works. I notice that the created object myFoo
doesn't inherit a method from Bar
if I assign the prototype after creating the object. Is there any way that we can make previous created objects to inherit prototype methods? Thanks
function Foo() {}
function Bar() {}
Bar.prototype.helloBar = function() {
console.log('hello bar!');
}
var myFoo = new Foo();
Foo.prototype = new Bar();
myFoo.helloBar();