Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda