split:
for (var i = 0; i < this.cells.length; i++)
length of cell , , -, i , .
:
var length = this.cells.length;
for (var i = 0; i < length; i++) {
, .
for (var i = this.cells.length - 1; i >= 0; i--)
.
, ,
this.cells.push({
coords: {
x: this.cells[i].coords.x + 50,
y: this.cells[i].coords.y
},
mass: this.mass,
velocity: {
x: this.cells[i].velocity.x,
y: this.cells[i].velocity.y
},
hue: this.cells[i].hue
});
this.cells.push({
coords: {
x: this.cells[i].coords.x + 50,
y: this.cells[i].coords.y
},
// this.mass is undefined, I believe you intend to get the current cell mass here.
mass: this.cells[i].mass,
velocity: {
x: this.cells[i].velocity.x,
y: this.cells[i].velocity.y
},
hue: this.cells[i].hue
});
. jsfiddle, reverse ver.