![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a question regarding the lifetime of a functions private variables. From my knowledge in other languages I would expect a functions private variables to be "unreachable" as soon as the function has finished executing (which in some other languages would pop off the variables from the stack) but it looks to me that javascript is working somewhat different. The following code shows that the private variable "i" can be reached by the both interval-functions after the functions scope is left - why is that ? Is this a "dirty" way to address the variable or is it fully supported ? snip |
#3
| |||
| |||
|
|
Johnny Nielsen wrote: I have a question regarding the lifetime of a functions private variables. From my knowledge in other languages I would expect a functions private variables to be "unreachable" as soon as the function has finished executing (which in some other languages would pop off the variables from the stack) but it looks to me that javascript is working somewhat different. The following code shows that the private variable "i" can be reached by the both interval-functions after the functions scope is left - why is that ? Is this a "dirty" way to address the variable or is it fully supported ? snip Formalised in ECMA 262, 3rd Ed. and also supported (more or less) in some preceding browser. See:- URL: http://jibbering.com/faq/faq_notes/closures.html Richard. |
#4
| |||
| |||
|
|
From my understanding it looks like these "closures" is something one should really be aware of when dealing with Ajax/webservice-based "static" pages where memory usage might build up. |
![]() |
| Thread Tools | |
| Display Modes | |
| |