If a function is nested way down many layers, how does the environment work then?
A: We used a simplistic way of showing the environment to explain it, but you can think of each nested function as having its own little environment with its own variables. Then, what we do is create a chain of the environments of all the nested functions, from inner to outer.
So, when it comes to finding a variable in the environment, you start at the closest one...
- 11. Anonymous Functions, Scope and Closures: Serious functions
- Publisher: O'Reilly Media, Inc.
- Released: March 2014
How nested functions look for the variables in their environment?