I have this class below and it seems my "getDatabaseStats()" method won't set my class' parameters. Logging "this.memberSince" within the method itself shows the correct result however the value remains null in the constructor or directly from my instance despite the method being called right before.
It doesn't seem to be a context problem as I still have access to the rest of the class' parameters and methods so I am very confused.
Edit - I just want to note that the rest of my code is asynchronous.
constructor(memberID){
...
this.memberID = memberID;
this.memberSince = null;
this.getDatabaseStats();
console.log(this.memberSince); // null
}
getDatabaseStats(){
const MySecondClass = require(`path to class`);
let sql = `My SELECT query`;
MySecondClass.database.query(sql, (error, rows) => {
...
this.memberSince = this.formatDate(rows[0].member_since);
console.log(this.memberSince); // 2020-07-06
console.log(this.memberID); // My member ID as normal
});
}
formatDate(date){
// Returns date formatted to YYYY-MM-DD
}