I use prototypal inheritance and want to have objects with instance arrays. So if I derive some objects from one object with an instance array and access the array, all of them share the array. I want to push something to the array and only change the array in the actual object, not in all others.
What is a elegent solution to this Problem with using standard prototypal inheritance and Object.create?
var sys = require('sys');
var obj ={
data: [],
add: function(what){
this.data.push(what)
}
};
var one = Object.create(obj);
one.add(1);
var other = Object.create(obj);
other.add(2);
sys.puts(other.data.length); // is 2, but should be 1