Steps:
Open page in Firefox 29.0.1 (Windows 7 x64):
<!doctype html>
<title>Test</title>
<script>
(function () {
var x = 5, f = function () {
setTimeout(f, 1000);
};
f();
}());
</script>
Open Developer Tools (F12).
In the Debugger, set a breakpoint on:
setTimeout(f, 1000);
Once the breakpoint is hit, evaluate
x
in the console. The result:undefined
Reload the page. The breakpoint is hit on the first run of
f
.Evaluate
x
. The result:5
Resume execution, and when the breakpoint is hit again, evaluate
x
. Same result:5
My assumption: If Firefox realizes on the first run of f
that x
is not needed, then it doesn't store the value of x
with f
. So in subsequent calls to f
the value of x
is undefined
. Interestingly, I see the same behavior in Chrome 35 and IE11.
Question: What is going on? Can I configure Firefox to make x
evaluate to its correct value in step 4 (see above)?