通过 node debug 进入 debugger ,在 repl 中打印无论 foo 还是 bar 都会报错, ReferenceError: foo is not defined 。
var foo = 0, bar = 0
process.nextTick(function() {
debugger
})
但是,只要在另外一个异步回调中"使用" foo 这个变量后,再次进入 debugger ,会发现 foo 已经可以访问,然而 bar 还是 ReferenceError 。
Google 了一会儿找不到答案...
var foo = 0, bar = 0
process.nextTick(function() {
console.log(foo)
})
process.nextTick(function() {
debugger
})