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.
(1) The closure of the mine led to large-scale redundancies. (2) The accident caused the complete closure of the road. (3) Several military bases are threatened with closure . (4) We haven't yet been told officially about the closure.
Closures are frequently used in JavaScript for object data privacy, in event handlers and callback functions, and in partial applications, currying, and other functional programming patterns.
If you want to be very formal in closing your business letter, consider using one of these phrases: Respectfully. Yours sincerely. Yours respectfully.
No, I think what it's saying is that N
is a function that has been returned from function F
, and therefore has access (through a closure) to variable b
which was declared inside F
. For example (live example):
function F() {
var b = 10;
return function () {
console.log(b);
};
}
var N = F(); //N is a reference to the anonymous function returned from F
N(); //logs '10' because we still have access to b (because of the closure)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With