Я хотел бы сделать запрос ajax, который все еще сохраняет доступ к текущему объекту. Кто-нибудь знает возможно ли это?Javascript OOP - jQuery, вызывающий «this» внутри ajax-запроса
Пример того, что я хотел бы сделать:
function mobile_as(as_object, inputID) {
this.object = 'something';
if (as_object) this.object = as_object;
this.inputID = inputID;
// Get results for later usage.
this.get_results = function(value) {
this.request = $.getJSON("URL", { as: this.object }, function (data) {
// Scope of "this" is lost since this function is triggered later on.
if (data['status'] == "OK") {
alert(this.inputID);
}
});
}
}
}
FYI JavaScript не ООП. – jrummell
@jrummell Это субъективно, не так ли? http://stackoverflow.com/questions/107464/is-javascript-object-oriented – teynon
Я думаю, что нет, но вы можете не согласиться. – jrummell