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);
}
};
}
この割り当てが失敗するのはなぜですか? jsの基本を知っていると思っていたのですが、これには困惑しています。さらに、可能な解決策は何ですか?最初にコンストラクターを呼び出して、そこに変数を設定しますか?
編集: 他のスクリプトでは次のように呼び出されます:
sc.addReadyPage(self.id);