JSFiddle - React, Tailwind, and code Playground
JavaScript
function Vector(x, y) {
if (x === undefined)
x = 0;
if (y === undefined)
y = 0;
this.x = x;
this.y = y;
}
function Rectangle(x, y, w, h) {
this.position = new Vector(x, y);
this.width = w;
this.height = h;
}
function GameObject() {
this.bounds = new Rectangle();
}
Test.prototype = new GameObject();
Test.prototype.constructor = Test;
function Test() {
this.bounds.width = 50;
this.bounds.height = 50;
}
var objects = [];
for (var i = 0; i < 3; i++) {
var test = new Test();
test.bounds.position = new Vector(i, 0);
alert(test.bounds.position.x);
objects.push(test);
}
for (var j = 0; j < objects.length; j++)
alert(objects[j].bounds.position.x);