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');