Question about local function declaration and invocation #7173
Unanswered
zms9110750
asked this question in
Q&A
Replies: 1 comment 2 replies
-
The variable is in scope where the function is lexically declared, but thanks to hoisting the function is in scope through the entire method. The compiler does normally enforce that the method can't be called until the captures are definitely assigned, but since you are only assigning a value to the variable it's perfectly safe to do that before the variable is definitely assigned. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Logically, a local function should be able to be declared anywhere, but only be invoked after capturing a variable. But the reality is the opposite, it must be declared after capturing a variable, but it can be invoked before the variable declaration. For example, in this code:
The local function
Hello5
captures the variablei5
, but it is declared afteri5
. However, it can be called beforei5
. How does this work?Beta Was this translation helpful? Give feedback.
All reactions