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

175
Visualizações
Unable to call Class data in Node.js

current output:

created card: Card {}

and because of that, this fails:

TypeError: Cannot read properties of undefined (reading '0')

My call function for creating a card:

function Prepare_units(Player) { // Player contains example data cards.
    var UnitHolder = [];
    Player.forEach(function (MinionUnit) {
        var CreatedCard = new Card.Card(MinionUnit);
        console.log("created card:",CreatedCard);
        CreatedCard.attack = CreatedCard.value[0];
        CreatedCard.health = CreatedCard.value[1];
        UnitHolder.push(CreatedCard);
    });

    return UnitHolder;
}

CardsData holds a promise (database call and return of spesific card)

call function in my Cards Class:

  constructor(MinionId) {
   this.CardsData(MinionId).then(data => {

            if (data) {
                this.card = data;

                console.log("collected data",data);
                this.attack = this.card.CardValue(0);
                this.health = this.card.CardValue(1);
                this.alive = true;
                this.deathrattle = this.card.deathrattle;
                return this;
            } else {
                console.log("error calling constructior, local set",data);
                this.Instance = "LOCAL";
                return this;
            }
         

         } );
    }

exports:

module.exports = {
    CardCreator : CardCreator,
    Card: Card,
}

Shouldnt i be able to call this.attack or createdCard.value from the Prepare_units method?

expected result is to get values from the card Class after creating a new instance.

Edit: I know why the properties are undefined. because it cant read it, but i dont know how to proceed to fix it.

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