N
news
First off, I KNOW this was a stupid thing to do and I've recoded the
function I was using to eliminate the parameter entirely, but I just
spent several hours debugging this and need to share
I have a function that calls itself via setTimeout and is occasionally
called directly. That function has an optional parameter which I was
relying on NOT begin set to anything (ie being undefined) when called
from the setTimeout, and being set to a particular number when called
directly.
Of the few browsers I've tested, IE8 and Opera 9.64 gives undefined
for all calls as you'd expected, but firefox 3.5.7 gives undefined for
the first call and then zero and the occasional random numbers as the
parameter value:
<html>
<head>
<title>timeout bug test</title>
<script type="text/javascript">
var timerDelay = 1000;
function doSomething(optionalParameter) {
var outputElement = document.getElementById('output');
outputElement.innerHTML += '<br>optionalParameter = '
+ optionalParameter;
window.setTimeout(doSomething, timerDelay);
}
</script>
</head>
<body onload="doSomething();">
<p id="output"></p>
</body>
</html>
The answer, as I've said, is don't do it this way. But the question
is, is this a bug in Firefox, or a case where the language behaviour
is not defined.
I'd appreciate people's thoughts.
Mike
function I was using to eliminate the parameter entirely, but I just
spent several hours debugging this and need to share
I have a function that calls itself via setTimeout and is occasionally
called directly. That function has an optional parameter which I was
relying on NOT begin set to anything (ie being undefined) when called
from the setTimeout, and being set to a particular number when called
directly.
Of the few browsers I've tested, IE8 and Opera 9.64 gives undefined
for all calls as you'd expected, but firefox 3.5.7 gives undefined for
the first call and then zero and the occasional random numbers as the
parameter value:
<html>
<head>
<title>timeout bug test</title>
<script type="text/javascript">
var timerDelay = 1000;
function doSomething(optionalParameter) {
var outputElement = document.getElementById('output');
outputElement.innerHTML += '<br>optionalParameter = '
+ optionalParameter;
window.setTimeout(doSomething, timerDelay);
}
</script>
</head>
<body onload="doSomething();">
<p id="output"></p>
</body>
</html>
The answer, as I've said, is don't do it this way. But the question
is, is this a bug in Firefox, or a case where the language behaviour
is not defined.
I'd appreciate people's thoughts.
Mike