I get an unexpected result with the following code:
var TestModel, u, u2;
function TestModel() {}
TestModel.prototype.a = null;
TestModel.prototype.b = [];
u = new TestModel();
u.a = 1;
u.b.push(1);
u2 = new TestModel();
u2.a = 2;
u2.b.push(2);
console.log(u.a, u.b); // outputs: 1 [1,2]
console.log(u2.a, u2.b); // outputs: 2 [1,2]
I find it surprising that u.b and u2.b contain the same values even though each instance of TestModel should have its own instance variables according to how I've setup the prototype. So this is the output I was expecting:
console.log(u.a, u.b); // expecting: 1 [1]
console.log(u2.a, u2.b); // expecting: 2 [2]
The same thing happens if I set b to be an object and set keys on it rather than using it as an array. What am I not understanding here?

