Quote from Stoyan Stefanov’s Object-Oriented JavaScript (page 84):

If you’re at point a, you’re inside the global space. If you’re at point b, which is
inside the space of the function F, then you have access to the global space and to
the F-space. If you’re at point c, which is inside the function N, then you can access
the global space, the F-space and the N-space You cannot reach from a to b, because
b is invisible outside F. But you can get from c to b if you want, or from N to b. The
interesting thing—the closure—happens when somehow N breaks out of F and ends
up in the global space.”
I think the bold sentence above should be changed to “If you’re at point c, which is inside the function N, then you can access the global space and the N-space ” (the F-space shouldn’t be contained, because the point c only has access to N-space and the global scope G. ).
Am I right? thanks.
As others have said, no.
Just about the whole point about a closure is that an external reference to an inner function keeps not only that inner function alive but also allows it to access the outer environment in which it was created, even if that outer environment arose from an executed function that has completed and returned.
I think the diagram would better illustrate closure if the blue
Nwere shown insideFand the dotted version (the reference toN) were shown outsideF.The last sentence of the quoted statement could also be improved :
Note that this version avoids mention of the global space. Any external scope will suffice for a closure to be formed.
The statement could go further to say that the mechanism which allows closures to be formed is the suppression of Garbage Collection.
Warning: There are many bad definitions and descriptions of “closure”, both on the web and in books. Stack Overflows’s current tag wiki entry for “closures” is a case in point.