Calling variables defined in outer function from inner function with debugger

后端 未结 1 396
小蘑菇
小蘑菇 2021-01-05 21:51

From the jQuery docs javascript guide:

Because local scope works through functions, any functions defined within another have access to variables d

相关标签:
1条回答
  • 2021-01-05 22:19

    Presumably this is an optimisation by the JavaScript engine. Since you're not referring to y within the inner function there is no need to hold on to it in the closure. This will allow it to be garbage collected when the outer function returns.

    If you add a reference to y (for example console.log(x, y)) you can see the values of both x and y as you would expect.

    isn't there some way to still call the variable y from the console inside the inner function?

    Apparently not. You could just add a reference to y within inner while debugging (it doesn't have to do anything, any reference will do).

    0 讨论(0)
提交回复
热议问题