Say we have the following example:
const Foo = {
init: function(who) {
this.me = who;
},
speak: function() {
console.log(this.me);
}
};
Then we have new objects whose prototype references foo:
const b1 = Object.create(Foo);
const b2 = Object.create(Foo);
b1.init("Kristopher");
b2.init("Jane");
b1.speak();
b2.speak();
The output is the following:
Kristopher
Jane
But I would have expected "this" to refer to the context of the prototype function. If each new object merely references the prototype, I thought the following would be output:
Jane
Jane
Why is this not the case? I thought that since Foo is the shared prototype of b1 and b2, that modifying this.me
would overwrite the variable for both b1 ad b2?