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

176
Vistas
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 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