I'm trying to have some object oriented design using JS and jQuery. I have the following construstor:
function A () {
this.url = "some url";
$("rrr").autocomplete({
source: function(req, add){
$.getJSON(this.url, req, function(data) {} ...
}
As you guessed, I can't use this.url, since jQuery redefienes this. I can't use just url without this, since it is not declared. What I came up is to have something like this:
function A () {
this.url = "some url";
var url = this.url;
$("rrr").autocomplete({
source: function(req, add){
$.getJSON(url, req, function(data) {} ...
}
But this is just plain ugly, and works only for properties.
Is there a better way to fetch value of this from original scope in jquery methods?