Why does Chrome debugger think closed local variable is undefined?

后端 未结 5 1067
庸人自扰
庸人自扰 2020-11-22 00:48

With this code:

function baz() {
  var x = \"foo\";

  function bar() {
    debugger;
  };
  bar();
}
baz();

I get this unexpected result:<

5条回答
  •  Happy的楠姐
    2020-11-22 01:41

    Like @Louis said it caused by v8 optimizations. You can traverse Call stack to frame where this variable is visible:

    Or replace debugger with

    eval('debugger');
    

    eval will deopt current chunk

提交回复
热议问题