I tried to iterate an array like this:
import { Vec2 } from './Math.js';
import Physics from "./Physics.js";
export default class Entity{
constructor(x, y, w, h) {
this.pos = new Vec2(x, y);
this.scale = new Vec2(w, h);
this.vel = new Vec2;
this.traits = [];
this.traits['physics'] = new Physics;
}
addTraits(name, trait) {
this.traits.push(trait);
}
updateTraits(deltaTime, level) {
//this.traits["physics"].update(deltaTime, this, level);
this.traits.forEach(trait => {
trait.update(deltaTime, this, level);
});
}
}
And neither the forEach
nor the function is executed.