|
|
|
|
|
by crazygringo
4733 days ago
|
|
If I'm understanding what you're saying, that's just not correct. Try and run this code: var a = function() {
var z = "a";
window.b = function() { z = "b"; }
window.c = function() { return z; }
};
a();
window.c(); // returns "a"
window.b();
window.c(); // returns "b"
As you can clearly see, the single closure containing the variable "z" is shared between functions b() and c().So each function does not have its own closure -- closures work "upwards", referencing everything in every scope above them. |
|