Every now and then I need to debug something in DevTools and I get this puzzling error:
That’s V8 optimizing the function and seeing that thing
isn’t used in the function and therefore not putting it into the closure scope. There are a couple of ways to break this optimization, one is to use thing
somewhere in the debugging function, however the problem with this is that you must enumerate all the vars you want to inspect. An easier technique I’ve found is to make it impossible for V8 to know what vars will be used in the function. What that entails is to just have a blank eval
in the function somewhere (I usually put in right before the debugger statement):