Javascript object function problem
Hi all,
I have a probelm I am trying to work around.
In the code below the id proprty is not visible in the "loadedFnc" function.
I am trying to do something asynchronously, thus am setting the onreadystatechange
property to be a function in the javascript object. However when I do this
the "this" does not see the properties of my object.
Am I being a little ambitous?
Regards
Sean
function xmlCache(pid)
{
this.id = pid;
this.load = xmlCacheLoad;
var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
this.HTTP = xmlHttp;
}
function xmlCacheLoad()
{
this.HTTP.onreadystatechange = this.loadedFnc;
}
function loadedFnc()
{
alert(this.id);
{
//do something
}
}
Re: Javascript object function problem
Sean,
Perhaps you could try calling the loadedFnc function and passing in "this"
as a parameter like so:
this.HTTP.onreadystatechange = loadedFnc(this);
Then set your function to accept parameters such as:
function loadedFnc(obj){
alert(obj.id);
return obj.id;
}
I don't know for certain that this will work, but it should give you some
perspective on other ways to look at the problem.
Kevin
Webmaster - JavaScript Solutions
http://www.javascriptsolutions.com
"sean" <sean@ireland.com> wrote:
>
>Hi all,
>I have a probelm I am trying to work around.
>
>In the code below the id proprty is not visible in the "loadedFnc" function.
>
>I am trying to do something asynchronously, thus am setting the onreadystatechange
>property to be a function in the javascript object. However when I do this
>the "this" does not see the properties of my object.
>
>Am I being a little ambitous?
>
>Regards
>Sean
>
>function xmlCache(pid)
>{
> this.id = pid;
> this.load = xmlCacheLoad;
> var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
> this.HTTP = xmlHttp;
>}
>function xmlCacheLoad()
>{
> this.HTTP.onreadystatechange = this.loadedFnc;
>}
>
>function loadedFnc()
>{
>alert(this.id);
>{
>//do something
>}
>}