我想知道是否有一個優雅的方法來做下面的代碼,而不必首先調用父對象「那個」。如果我嘗試從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();
這是唯一我沒有這麼遠的工作。我會嘗試你的建議!謝謝! – 2013-02-20 00:31:02