javascriptでオブジェクトメソッドを宣言しています。このメソッド内で ajax 呼び出しを行い、呼び出しが完了したら、このオブジェクトのいくつかの属性を変更します。
Bubble.prototype.draw = function(){
console.log(this.attribute) // -> works fine
var req = $.ajax({
url: "someFile.php",
type: "post",
data: someData
});
// handle response
req.done(function (response, textStatus, jqXHR){
console.log(this.attribute) // -> not in the scope, obviously
});
}
this.attribute
のスコープに入れるにはどうすればよいreq.done
ですか? Bubble
内のオブジェクト全体にアクセスするにはどうすればよいreq.done
ですか? 現在、すべての はBubble
配列内にあるため、この配列のインデックスを渡すだけで、この方法でプロパティにアクセスできます ( array[i].attribute
)。これを行うにはもっと良い方法があると思います。