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

299
Views
Cómo corregir un TypeError no detectado: this.newTarget no es una función

Cuando llamo a newTarget desde la función tileClick en la clase Game, aparece el error "Uncaught TypeError: this.newTarget is not a function", pero cuando lo ejecuto desde la función Start, no recibo ningún error y realmente no lo hago. entender porqué

Aquí está mi código javascript:

 function Start() { tiles = document.querySelectorAll(".tile"); var game = new Game(600, 15000, tiles, "playername"); tiles.forEach((tile) => { tile.addEventListener("click", game.tileClick); tile.isTarget = false; tile.style.background = "grey"; }); game.newTarget(); } class Game { constructor(interval, maxTime, tiles, player) { this.points = 0; this.player = player; this.maxTime = maxTime; this.interval = interval; this.tiles = tiles; this.startTime = Date.now(); document.getElementById("points").textContent = this.points; } newTarget() { if (Date.now() - this.startTime > this.maxTime) { clearInterval(this.timer); alert("Game over, you got: " + this.points + " points!"); return; } tiles.forEach((tile) => { tile.isTarget = false; tile.style.background = "grey"; }); var target = Math.floor(Math.random() * tiles.length); tiles.item(target).isTarget = true; tiles.item(target).style.background = "red"; this.timer = setInterval(this.newTarget, this.interval); } tileClick(event) { if (Date.now() - this.startTime > this.maxTime) { return; } this.tile = event.target; if (this.tile.isTarget) { console.log(this.points); this.points++; document.getElementById("points").textContent = this.points; clearInterval(this.timer); this.newTarget(); } } }
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!