|
|
|
|
|
by Dylan16807
4733 days ago
|
|
> I just always assumed that all the variables present in a closure are maintained, if there's an existing reference to any function defined within. In the logical sense each function has its own closure. There is no way functions should affect which[edit for clarity] variables are closed on by each other. So you shouldn't expect this. >I'm actually suprised/impressed that Chrome has an optimization to detect which closure variables are actually used in a function and garbage-collect the rest. In the logical sense functions close over their variables, not all variables that happen to be in scope. So that optimization is needed. |
|
So each function does not have its own closure -- closures work "upwards", referencing everything in every scope above them.