Why when I instantiate a new object in JavaScript that has another object as one of its properties, does it always reference the same object?
For example
function test() {}
test.prototype.state = {
num: 0
};
var obj1 = new test();
var obj2 = new test();
obj1.state.num = 1;
console.log(obj1.state.num,obj2.state.num); // Outputs 1 1 instead of 1 0
Also, what would be the appropriate way to make it create a new object property every time it is instantiated?