Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!