Not a problem, because I found out what causes it, but a huge quirk nevertheless:
Apparently when you create a closure, the JavaScript engine does not save all of its scope variables. It saves only the ones that are really used by the inner function. This causes incorrect results in the debugger if you halt your program. Here is how you can reproduce this
1.Run the following snippet in Chrome:
function foo (){
var id = 0
var id2 = 1
return function foo2(){
//console.log(id)
console.log(id2)
debugger
}
}
foo()()
Notice that only id2 is defined in the closure scope:
2.Uncomment the console.log statement.
There are now two variables in the closure scope
Does someone know why this happens (I presume it is to save memory) and are there any other aspects of this that we should be aware of.