View Single Post
  #4 (permalink)  
Old Feb 10th, 2008, 04:09
Rakuli's Avatar
Rakuli Rakuli is offline
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: .call or .apply with setTimeout

That's right, you can't use the this keyword because it is not available in the scope from where you're calling it.

You can look at naming the obj so it can be aware within the function:

Code: Select all
function hello(objName)
{
    this.i=0;
    this.Oname = objName;
    this.bye();
    
    alert(this.i);
}
hello.prototype.bye = function()
    {this.i++;}
hello.prototype.timeOut = function()
{setTimeout(this.Oname + '.this.seti()', [20]);}, 1000);}
hello.prototype.seti = function(l)
{
    this.l=l;
    this.i=l;
    this.bye();
}
Then when you create the object, pass the name of the variable to the obj.

var jim = new hello('jim');
Reply With Quote