I am new to Javascript and call back functions. is this the correct way to do a call back? when i test i get an infinite loop. I want to retrieve from the database and store in an object's variable to use in getSport().
constructor(matchid) {
this.hasLoaded = false;
this.matchid = mid;
this.Match = {
"sport": "baskt",
"winner": -1,
};
}
rload(callback) {
this.hasLoaded = true;
matchDataBaseRef.child(this.mid)
.on("value", function (snapshot) {
this.Match = snapshot.val();
callback();
});
}
get getSport() {
if (!this.hasLoaded) {
this.rload(this.getSport);
}
return this.Match['sport'];
}