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

194
Vistas
How to create a function for adding an object created by the same function into array?

I am creating html game where i generate platforms by manually adding them into the array platforms, therefore I created a function that will adding objects into that array. But it throws an error:

canvas.bundle.js:230 Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))

let generation = ( object, array, image, y ) => {
  array = [... array, new object({
    x: LastPos, y, image
  })]
  LastPos = image.width + Math.floor(Math.random() * 1000)
}

generation(Platform,platforms,platformImage,470)
  • The reason to create that function is the attempt to make infinity game (runner)

the function execution will be in the loop

P.S object to be generating is the class:

class Platform {  
  constructor({x, y, image}) {
    this.position = {
      x, y
    }
    this.image = image
    this.width = image.width
    this.heigth = image.height

  }
  draw() {
    c.drawImage(this.image, this.position.x, this.position.y)
  }
}
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