I have a class, looks something like this:
function MyClass()
{
this.array1 = [];
this.array2 = [];
this.add_item = function( i_x, i_y, i_item )
{
var pos = { "x" : i_x, "y" : i_y, "data" : i_item };
this.array1.push( pos );
this.array2.push( pos );
}
return this;
}
What is happening is that when I put a breakpoint at the second row of the add_item method (the this.array1.push row) both array1 and array2 already have the pos item! When I step forward one step, both arrays receive the pos item again!
The unlikely answer is that this is a bug in Firefox. I experimented a bit earlier with prototyping in methods into Object, but then read that that could lead to problems with for-each-loops. What could be causing this? Is the old code still bouncing around in there? I need a clue. I’ve removed all Array and Object prototype code I had. I’ve restarted firefox. Nothing helps. Any ideas?
It turns out the problem was with the firebug debugger. It was not showing the actual array. I’m not sure what it is showing, but I implemented my own object-printing-method (that handles cyclic object references) and it turns out the arrays are correct.
phew thought I was going nuts there for a while.