I'm setting up my javascript objects like the following
Object1 = function() {
var privateMember = "private value"
return {
publicMember: "public value"
setPrivateMember: function(value) {
privateMember = value;
}
}
}();
Now if I use prototypal inheritance to create new objects
Object2.prototype = Object1
And then set the private member
Object2.setPrivateMember("new value");
Then the value of private member in Object 1 changes too, so it behaves more like a static variable. Is there a way I can get private variables to not be static?
PS - I'm a self-taught programmer so my use of terminology might be a bit sketchy. Let me know if it needs clarifying