Hi,
I have this piece of code, and it doesn't work as I expect (it's demo code, distilled from a larger program):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Test</title>
<script language="javascript" type="text/javascript">
var test = {
variable: true,
go: function() {
alert(this.variable);
}
};
function s() {
test.go();
setTimeout(test.go, 500);
}
</script>
</head>
<body>
<form action="#">
<input type="button" value="Go" onclick="s();" />
</form>
</body>
</html>
When I click the Go button, both in IE and FF (the only browsers I care about atm), the first alert box shows "true", the second one "undefined".
My questions are why, and how can I avoid it?