Twitter | Pretraživanje | |
Nathanael Anderson 27. stu
Odgovor korisniku/ci @v8js @bmeurer @mathias
Simple code is: function bodyOnLoad() { const outerValue = 'ipsum'; function inner() { var innerVaue = 'test test'; debugger; } inner(); }
Reply Retweet Označi sa "sviđa mi se"
Benedikt Meurer 27. stu
Odgovor korisniku/ci @CongoCart @v8js i 2 ostali
The engine optimizes away the `outerValue` from the closure for `inner`, since it's no needed. So has no way to get to its value.
Reply Retweet Označi sa "sviđa mi se"
Nathanael Anderson 27. stu
Odgovor korisniku/ci @bmeurer @v8js i 2 ostali
initially that was my idea, but it still wasn't available in the inner, when it is used after it. function onLoad() { const oValue = 'ipsum'; function inner() { var innerVaue = 'test test'; debugger; } inner(); console.log(Value); }
Reply Retweet Označi sa "sviđa mi se"
Nathanael Anderson 27. stu
Odgovor korisniku/ci @bmeurer @v8js i 2 ostali
Lol, last line should be `console.log(oValue);` so shouldn't oValue still be available since it has to be used AFTER inner() is called?
Reply Retweet Označi sa "sviđa mi se"
Benedikt Meurer 27. stu
Odgovor korisniku/ci @CongoCart @v8js i 3 ostali
Reply Retweet Označi sa "sviđa mi se"
Toon Verwaest 27. stu
Odgovor korisniku/ci @bmeurer @CongoCart i 3 ostali
No, oValue is referenced from the function itself so is still not context allocated. Only gets context allocated if an inner function references it (or if there's an eval).
Reply Retweet Označi sa "sviđa mi se"
Nathanael Anderson 27. stu
Odgovor korisniku/ci @tverwaes @bmeurer i 3 ostali
Seems strange to me that oValue is not known by the debugger at that point since it is still allocated; and in the parent scope. This creates a bit of debugging pain when you are dealing with Lamda's and things like .map, .reduce, etc.
Reply Retweet Označi sa "sviđa mi se"
Nathanael Anderson 27. stu
Odgovor korisniku/ci @tverwaes @bmeurer i 3 ostali
The v8 engine knows what the value is; but the debugger doesn't. In this example; eval got the value and returned it -- but while in inner() the debugger still has no clue.
Reply Retweet Označi sa "sviđa mi se"
Nathanael Anderson 27. stu
Odgovor korisniku/ci @tverwaes @bmeurer i 3 ostali
So would this be something you think a feature request to enhance the tooling to change it to work the way a developer would assume it would work. (i.e. child scopes can see parent scope values, just like code can. )
Reply Retweet Označi sa "sviđa mi se"
Toon Verwaest 28. stu
Odgovor korisniku/ci @CongoCart @bmeurer i 4 ostali
In general this doesn't work ("onLoad" can finish and destroy "oValue" before "inner" is called), but I agree that it may make sense to provide access to values when they are still available; especially for .map etc.
Reply Retweet Označi sa "sviđa mi se"
Yang Guo
Pro-tip: if the function is still on the stack, select the stack frame to see the stack locals.
Reply Retweet Označi sa "sviđa mi se" More
Nathanael Anderson 28. stu
Odgovor korisniku/ci @hashseed @tverwaes i 4 ostali
Awesome pro-tip. 👏
Reply Retweet Označi sa "sviđa mi se"
Yang Guo 28. stu
Odgovor korisniku/ci @tverwaes @CongoCart i 4 ostali
You might then ask why this doesn't happen automatically. Well, the function may be on the stack several times, e.g. in a recursion, so the same variable may have different values depending on which stack frame it belongs to.
Reply Retweet Označi sa "sviđa mi se"
Nathanael Anderson 1. pro
Odgovor korisniku/ci @hashseed @tverwaes i 4 ostali
Not sure I understand even in recursion, seems like if the VALID value is accessible by clicking the prior callstack frame, then if the lambda doesn't have the value in its stack, then it auto-walks back the stack (just like a click would) to get the valid from the outer frames.
Reply Retweet Označi sa "sviđa mi se"
JSW 29. stu
Odgovor korisniku/ci @hashseed @ChromeDevTools i 5 ostali
Is there any visual way to show scope depth like a highlight color gradient for every function that goes deeper. Very pale blue towards a darker blue, with current line as green?
Reply Retweet Označi sa "sviđa mi se"
JSW 29. stu
Odgovor korisniku/ci @hashseed @ChromeDevTools i 5 ostali
Like a topography map! But in blue
Reply Retweet Označi sa "sviđa mi se"
Ian Leon 30. stu
Odgovor korisniku/ci @hashseed @ChromeDevTools i 5 ostali
Using Linux on the desktop like a boss
Reply Retweet Označi sa "sviđa mi se"