New solution
You forgot 3 times the keyword new:
return (Vector2D(that.x + other.x, that.y + other.y)); // line 92
return (Vector2D(that.x - other.x, that.y - other.y)); // line 96
metaList.push(createBlock(i)); // line 133
You have to write
return (new Vector2D(that.x + other.x, that.y + other.y)); // line 92
return (new Vector2D(that.x - other.x, that.y - other.y)); // line 96
metaList.push(new createBlock(i)); // line 133
Just with the new keyword the this parameter of the functions is set to a new value. Here the code: http://jsfiddle.net/6eB3U/1/
Old solution
Here you have a debugged example of your code: http://jsfiddle.net/8ET77/
Consider the function createBlock():
function createBlock(idx)
{
var tmp = new Array(4);
for (var i = 0; i < 4; i++) {
if (i < 2)
tmp[i] = Math.round(Math.random() * 1000) % 600;
else
tmp[i] = Math.round(Math.random() * 10) % 4;
}
this.pos = new Vector2D(tmp[0], tmp[1]);
this.vec = new Vector2D(tmp[2], tmp[3]);
this.$block = $("#block"+idx);
return this;
}
For each call on the function, the reference this points to the same object (i.e. the function object createBlock()). The corrected function now looks like this:
function createBlock(idx)
{
var tmp = new Array(4);
for (var i = 0; i < 4; i++) {
if (i < 2)
tmp[i] = Math.round(Math.random() * 1000) % 600;
else
tmp[i] = Math.round(Math.random() * 10) % 4;
}
block = {}; // new object is generated here!
block.pos = new Vector2D(tmp[0], tmp[1]);
block.vec = new Vector2D(tmp[2], tmp[3]);
block.$block = $("#block"+idx);
return block;
}
You have to make the same correction for the function Vector2D().
$.eachto iterate over your list. Consider also to debug your code and see ifb.$blockis really a jQuery object. If it's just an element you can wrap it inside$(element)to make jQuery collection from it.