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

172
Views
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
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!