Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
Cannot read properties of undefined (reading 'Update') JavaScript

I'm trying to make a very basic TypeScript GameEngine but i have a cannot read properties of undefined error has occured and i don't understand why.

This is the error:

Uncaught TypeError: Cannot read properties of undefined (reading 'Update') at u (TSEngine.js:24:14)

My code before converting to javascript:

import Vector2 from "./class/Vector2.js";
import Square from "./class/Square.js";

export default class TSEngine {
  indexFileName: string;
  s: Square;
  v: Vector2;

constructor(indexFileName: string) {
  this.indexFileName = indexFileName;
}

Vector2(x: number, y: number): Vector2 {
    this.v = new Vector2(x, y);
    return this.v;
}

Square(position: Vector2, size: number, color: string): Square {
    this.s = new Square(position, size, color);
    return this.s;
}

Update(toUpdate: () => void): void {
    if(toUpdate) {
        toUpdate();
    }
}

u(deltaTime: number): void {
    this.Update(() => {});
    requestAnimationFrame(this.u)
  }

}

My code after converting to javascript:

import Vector2 from "./class/Vector2.js";
import Square from "./class/Square.js";
export default class TSEngine {
constructor(indexFileName) {
    this.indexFileName = indexFileName;
}
/*getBasePath(): string {
    return this.indexFileName;
}*/
Vector2(x, y) {
    this.v = new Vector2(x, y);
    return this.v;
}
Square(position, size, color) {
    this.s = new Square(position, size, color);
    return this.s;
}
Update(toUpdate) {
    if (toUpdate) {
        toUpdate();
    }
}
  u(deltaTime) {
    this.Update(); /// it shows me the error here
    requestAnimationFrame(this.u);
  }
}

I've tryed to put the 'Update' function above but it doesn't do anything

Edit I'm trying to use this function like that:

Engine.Update(() => {
   // the things to update
})

I've put a console.log in the Engine.Update function but it only showed once.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda