The code is pasted here.
I basically have a custom object which contains a XMLHttpRequest object inside it.
Inside my object's declaration I have the following.
this.oXMLHttp.onreadystatechange = function()
{
self.handleReadyStateChange();
};
which is setting the onreadystatechange event to a prototype function within the object called handleReadyStateChange.
I am having to use this "self" hack so I can obtain a reference to the current object with "this" from inside handleReadyStateChange, which I have documented next.
AjaxObject.prototype.handleReadyStateChange = function()
{
/*
* Author: Chris Miles
* Name: handleReadyStatusChange
* Purpose: Called when the status of the XMLHttpRequest object's state changes.
* Params: none
* Returns: none
*/
if((this.oXMLHttp.readyState === XMLHTTP_INTERACTIVE))
{
this.bHasBeenInteractive = true;
}
if((this.oXMLHttp.readyState === XMLHTTP_COMPLETED))
{
if(this.bHasBeenInteractive === true)
{
this.fCallBack(this.oXMLHttp.responseText);
}
else
{
alert("request completed but, never went through the correct stages");
}
}
}
Now this code works perfectly save for the fact I am leaking memory with the closure at the top.
Is there another solution (cleaner hopefully), so when handleReadyStateChange is called it can access the current instance of the object it belongs to.
thanks
Chris
I basically have a custom object which contains a XMLHttpRequest object inside it.
Inside my object's declaration I have the following.
this.oXMLHttp.onreadystatechange = function()
{
self.handleReadyStateChange();
};
which is setting the onreadystatechange event to a prototype function within the object called handleReadyStateChange.
I am having to use this "self" hack so I can obtain a reference to the current object with "this" from inside handleReadyStateChange, which I have documented next.
AjaxObject.prototype.handleReadyStateChange = function()
{
/*
* Author: Chris Miles
* Name: handleReadyStatusChange
* Purpose: Called when the status of the XMLHttpRequest object's state changes.
* Params: none
* Returns: none
*/
if((this.oXMLHttp.readyState === XMLHTTP_INTERACTIVE))
{
this.bHasBeenInteractive = true;
}
if((this.oXMLHttp.readyState === XMLHTTP_COMPLETED))
{
if(this.bHasBeenInteractive === true)
{
this.fCallBack(this.oXMLHttp.responseText);
}
else
{
alert("request completed but, never went through the correct stages");
}
}
}
Now this code works perfectly save for the fact I am leaking memory with the closure at the top.
Is there another solution (cleaner hopefully), so when handleReadyStateChange is called it can access the current instance of the object it belongs to.
thanks
Chris