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

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