T
trib
Hi,
I'm reasonably new to OO javascript, but appreciating it's versatility.
I'm trying to do an XMLHTTP request from an instance method of a
object defined by a class, and I would normally embed the response
handler in the function, like so:
var req = newXmlHttp();
req.open("GET", url, true);
// When the response is received, process it
req.onreadystatechange = function() {
if (req.readyState == 4) {
..etc...
}
}
But, if req is an instance property, and is referenced as this.req, it
does not seem to be available within the scope of the inline function.
As a workaround I'm currently defining the handler function as a
separate instance method, and setting up the event handler like so:
var thisobj= this;
this.req.onreadystatechange = function () { thisobj.processResponse()
};
Is there any way to keep it as an inline function?
Cheers,
Andrew
I'm reasonably new to OO javascript, but appreciating it's versatility.
I'm trying to do an XMLHTTP request from an instance method of a
object defined by a class, and I would normally embed the response
handler in the function, like so:
var req = newXmlHttp();
req.open("GET", url, true);
// When the response is received, process it
req.onreadystatechange = function() {
if (req.readyState == 4) {
..etc...
}
}
But, if req is an instance property, and is referenced as this.req, it
does not seem to be available within the scope of the inline function.
As a workaround I'm currently defining the handler function as a
separate instance method, and setting up the event handler like so:
var thisobj= this;
this.req.onreadystatechange = function () { thisobj.processResponse()
};
Is there any way to keep it as an inline function?
Cheers,
Andrew