私はjsオブジェクトを持っています。私は別のメソッドを呼び出して約束を返しますが、.then()の中からメンバー関数foo()にアクセスすることはできません。なぜfoo()にアクセスできないのですか?どのようにアクセスできますか?ここに私のコードは次のとおりです。この上の任意の助けを約束の中からオブジェクトのメソッドをどのように呼び出すのですか?()?
function LoadImageGroupFormat() {
return new Promise(function(resolve, reject) {
var xhttp = new XMLHttpRequest();
xhttp.open('GET', "imagegroup_format.txt");
xhttp.onload = function() {
if (xhttp.status == 200) resolve(xhttp.responseText);
else reject(Error(xhttp.statusText));
};
xhttp.onerror = function() {
reject(Error("Network Error"));
};
xhttp.send();
});
}
//the object
var Registerhandler = {
imageGroupIndex: 0,
foo: function() {
//Do something else here
},
GetImageGroupFormat: function() {
var imageGroupIndex = this.imageGroupIndex;
LoadImageGroupFormat().then(function(ImageGroup_Format) {
//Do something with ImageGroup_Format
imageGroupIndex++; //This works
foo(); //Doesn't work - undefined
}, function(error) {
console.error("Failed to Load ImageGroup Format", error);
});
}
}
感謝。
'imageGroupIndex ++;' "作品" あなたはローカル変数 'imageGroupIndex'を作ったので、それはRegisterhandler.imageGroupIndex' –
がどのように私は、インスタンスの変数を変更します'修正イマイチ? –