E
Emanuele D'Arrigo
Hi everybody,
in the small snippet of code below, you can see two identical
debugMsg(this.myname) statements, one correctly returns "manu"
but the other returns "undefined". This is due to 'this' getting out
of scope. Is there a way I can retain the 'this' object inside the
function() block? So that I can affect the object calling this method
from there? Any workarounds instead?
Here's the code:
----------------------------------------------
function AreasManager()
{
this.myname = "manu";
}
AreasManager.prototype.addAreasFromXmlFile = function(xmlFile_)
{
debugMsg(this.myname);
var request = GXmlHttp.create();
request.open("GET", xmlFile_, true);
request.onreadystatechange = function()
{
if (request.readyState == 4)
{
var xmlContent = request.responseXML;
debugMsg(this.myname);
}
}
request.send(null);
}
in the small snippet of code below, you can see two identical
debugMsg(this.myname) statements, one correctly returns "manu"
but the other returns "undefined". This is due to 'this' getting out
of scope. Is there a way I can retain the 'this' object inside the
function() block? So that I can affect the object calling this method
from there? Any workarounds instead?
Here's the code:
----------------------------------------------
function AreasManager()
{
this.myname = "manu";
}
AreasManager.prototype.addAreasFromXmlFile = function(xmlFile_)
{
debugMsg(this.myname);
var request = GXmlHttp.create();
request.open("GET", xmlFile_, true);
request.onreadystatechange = function()
{
if (request.readyState == 4)
{
var xmlContent = request.responseXML;
debugMsg(this.myname);
}
}
request.send(null);
}