I'm trying to get my head around protoypal inheritance and have a question about shared member variables.
I have an object:
var objA = {
list: [],
myPush: function(aParam){
this.list.push(aParam);
}
}
and try to "protoypal inherit" it with the object() function from http://javascript.crockford.com/prototypal.html
var objB = object(objA);
but somehow a change to objA gets transfered to objB:
objA.myPush('a string');
equals(objA.list.length, 1);
equals(objB.list.length, 0); //<= Fails. Why?
The full code with failing tests: http://jsbin.com/izawi/edit
Could someone explain this to me? And possible fixes. I could have an constuct() function, but this doesn't seems right.
Thanks in advance
Matthias