var sc = new stuCore();
function stuCore() {
this.readyPages = [];
this.once = true;
var self = this;
// gets called asynchronously
this.doPrepPage = function (page){
if(self.once == true){
// still gets executed every time, assignment fails
self.once = false;
doSomeStuffOnce();
}
};
this.addReadyPage = function (pageid) {
console.log("readypage called");
this.readyPages.push(pageid);
if (!$.inArray(pageid, self.readyPages) != -1) {
this.doPrepPage(pageid);
}
};
}
why does this assignment fail? I thought I knew the basics of js, but I'm stumped by this. And furthermore what would be a possible solution? call a constructor first and set the variable there?
EDIT: gets called like this in some other script:
sc.addReadyPage(self.id);
// gets called asynchronouslyHow exactly are you calling it? How are you callingstuCore? It works fine for me: jsfiddle.net/fkling/KwRKfthisat the moment you assign it to self?doPrepPageat least once for every instance you create. Either you provide one yourself, which shows the problem, or we cannot help you.