最初に親オブジェクトを「それ」と呼び出す代わりに、次のコードを実行するエレガントな方法があるかどうか疑問に思っていました。ajax リクエスト内から「this」を使用しようとすると、明らかに Ajax オブジェクトを参照します。
少なくとも私はその意味だと思います。
var ObjectA = Class.create();
ObjectA.prototype = {
initialize: function() {
//Workaround I use
that = this;
},
getData: function(bounds) {
//ajax to get some data
url = "http://www.data.com/";
new Ajax.Request(url, {
method: 'get',
onSuccess: function(response) {
// Handle the response content...
that.workData(response.responseText);
//THIS IS MY DOUBT.
//How do I access the parent object without having to previously calling it "that" first?
}
});
},
workData: function(data){
//do something with the data
}
}
var test = new ObjectA();
test.getData();