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

273
Visualizações
Javascript Class attributes undefined with "Callback Hell" Syntax

so I'm trying to make a node package for the Roblox API, and inside of it, I have decided taking a OOP approach. The issue comes in when attributes such as <RobloxUser>.id are showing up as undefined unexpectedly, I added console.log statements and the API calls are returning the expected values.

Originally I added an async IIFE inside the class constructor to make calls using async/await syntax and I was having this issue. So I figured it was a scoping issue or something of the sort and changed my syntax to "callback hell" styled syntax and am still having this issue.

To test my theory I set a variable <RobloxUser>.test = 0 then used console.log, it printed 0 as expected, then I set it equal to 2 inside the callback and printed it outside the callback and it printed 0 again.

In all my time working with Javascript I have never once had an issue similar to this, if anyone may offer me some insight as to how I can solve this problem I would greatly appreciate it.

RobloxUser class code:

class RobloxUser {
    constructor(response) {
        axios.get(`https://users.roblox.com/v1/users/${response.data.Id}`).then(res => {
            this.username = res.data.name;
            this.displayName = res.data.displayName;
            this.id = res.data.id;    
                
            this.info = { };
        
            let joinDate = new Date(res.data.created);
            let now = new Date();
                
            this.info.accountAge = Math.round(Math.abs((joinDate.getTime() - now.getTime()) / (24 * 60 * 60 * 1000)));
            this.info.isBanned = res.data.isBanned;
        });

        axios.get(`https://friends.roblox.com/v1/users/${this.id}/friends/count`).then(res => {
            this.info.friendCount = res.data.count;
        });
        
    
        axios.get(`https://friends.roblox.com/v1/users/${this.id}/followings/count`).then(res => {
            this.info.followingCount = res.data.count;
        });
    
        axios.get(`https://friends.roblox.com/v1/users/${this.id}/followers/count`).then(res => {
            this.info.followerCount = res.data.count;
        });
    
        axios.get(`https://users.roblox.com/v1/users/${this.id}/username-history`).then(res =>  {
            this.info.pastUsernames = res.data.data.map(data => data.name)
        });
    }

    getThumbnailURL() {
        
    }
}
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