T
Telmo Costa
I have a HTML page with a form with 2 buttons like this
....
<input type="button" value="Add" onClick="ClickAdd();"/>
<input type="button" value="Reset" onClick="ClickReset();"/>
....
I also have this javascript code:
----------------------------------------
function ClickAdd() {
setTimeout(test.Add, 100);
//test.Add();
};
function ClickReset() {
setTimeout(test.Add, 100);
//test.Reset();
};
Test = function () {
this.total = 0;
};
Test.prototype.Add = function() {
this.total++;
alert(this);
};
Test.prototype.Reset = function(i) {
this.total = 0;
alert(this);
};
Test.prototype.toString = function() {
return (this.total);
};
test = new Test();
-------------------------------------------
the thing is:
in the ClickAdd function, if i call test.Add() directly, is works ok
But if I call it using setTimeout, the /alert(this)/ shows
[object Window]
Why? And what should i do to make it work as i want?
....
<input type="button" value="Add" onClick="ClickAdd();"/>
<input type="button" value="Reset" onClick="ClickReset();"/>
....
I also have this javascript code:
----------------------------------------
function ClickAdd() {
setTimeout(test.Add, 100);
//test.Add();
};
function ClickReset() {
setTimeout(test.Add, 100);
//test.Reset();
};
Test = function () {
this.total = 0;
};
Test.prototype.Add = function() {
this.total++;
alert(this);
};
Test.prototype.Reset = function(i) {
this.total = 0;
alert(this);
};
Test.prototype.toString = function() {
return (this.total);
};
test = new Test();
-------------------------------------------
the thing is:
in the ClickAdd function, if i call test.Add() directly, is works ok
But if I call it using setTimeout, the /alert(this)/ shows
[object Window]
Why? And what should i do to make it work as i want?