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); }
-
-
Odgovor korisnicima @CongoCart @bmeurer i sljedećem broju korisnika:
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?
1 reply 0 proslijeđenih tweetova 0 korisnika označava da im se sviđa -
Odgovor korisnicima @CongoCart @v8js i sljedećem broju korisnika:
cc
@tverwaes1 reply 0 proslijeđenih tweetova 0 korisnika označava da im se sviđa -
Odgovor korisnicima @bmeurer @CongoCart i sljedećem broju korisnika:
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).
0 proslijeđenih tweetova 0 korisnika označava da im se sviđa -
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.
1 reply 0 proslijeđenih tweetova 0 korisnika označava da im se sviđa -
Odgovor korisnicima @CongoCart @tverwaes i sljedećem broju korisnika:
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.pic.twitter.com/CXsF46Uuen
0 proslijeđenih tweetova 0 korisnika označava da im se sviđa -
Odgovor korisnicima @CongoCart @tverwaes i sljedećem broju korisnika:
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. )
1 reply 0 proslijeđenih tweetova 1 korisnik označava da mu se sviđa -
Odgovor korisnicima @CongoCart @bmeurer i sljedećem broju korisnika:
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.
@hashseed0 proslijeđenih tweetova 0 korisnika označava da im se sviđa -
Odgovor korisnicima @tverwaes @CongoCart i sljedećem broju korisnika:
Pro-tip: if the function is still on the stack, select the stack frame to see the stack locals.pic.twitter.com/yiBARGCUZ7
9 proslijeđenih tweetova 29 korisnika označava da im se sviđa -
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.
0 proslijeđenih tweetova 4 korisnika označavaju da im se sviđa
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.
-
-
Odgovor korisnicima @CongoCart @tverwaes i sljedećem broju korisnika:
Consider this: function f(g, x) { let a=x; if (g) g(); return function() { debugger; } } f(f(undefined, 1), 2); At the break, should DevTools show 1 or 2 for `a`?
1 reply 0 proslijeđenih tweetova 1 korisnik označava da mu se sviđa -
Well there are two ways to deal with this... 1. treat `debugger` as `eval('debugger;')` in the engine; so that EVERYTHING is captured at that point. (i.e. console(a) will output '1') 1/
1 reply 0 proslijeđenih tweetova 0 korisnika označava da im se sviđa - Još 8 drugih odgovora
Novi razgovor -
Čini se da učitavanje traje već neko vrijeme.
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.