... I'm currently facing a situation where I have an object:
function Page(daoService) {
this.daoService = daoService;
this.gamesList = this.daoService.getGamesList();
}
// Rendering thumbs for main page
Page.prototype.renderThumbs = function(idContainer){
var container = document.getElementById(idContainer);
for (var i = 0; i < this.gamesList.length; i++) {
var thumbNode = document.createTextNode("<div class='thumbIcon'></div>");
thumbNode.style.backgroundImage = Const.PATH_THUMBS + this.gamesList.gameTitleseo;
container.appendChild(thumbNode);
}
};
In addition, there is a function in my code that utilizes the aforementioned object:
document.onreadystatechange = function() {
if (document.readyState == "interactive") {
// Initialization of elements
// Setting global dao service
var daoService = AjaxService();
// Initialization for page object
var page = new Page(daoService);
page.renderThumbs("homePageContainer");
}
}
The problem I am encountering is that when I call page.renderThumbs, the field this.gamesList has not yet been initialized as it is waiting for an ajax response from the server. Can someone provide guidance on how to address this issue and suggest any necessary changes to my approach? Thank you.