class Simulator {
constructor() {
this.gates = Array();
this.gates.push(new AndGate(200, 200));
}
initialize() {
let canvas = document.getElementById('board');
canvas.width = 800;
canvas.height = 500;
canvas.setAttribute("style", "border: 1px solid black");
this.gates.push(new AndGate(100, 100));
}
run() {
setTimeout(this.onLoop, 1000);
}
onLoop() {
for (let gate of this.gates) {
gate.render();
}
}
}
let sim = new Simulator();
sim.initialize();
sim.run();
For some reason, the JS transpiled version of my TypeScript class throws an error in the onLoop function. It reports TypeError: this.gates is undefined. However, if I access sim (a Simulator object) and manually access the gates property it's defined. I can run the onLoop code manually from the console.