I came across to this example:
function countMyself() {
// Check to see if the counter has been initialized
if ( typeof countMyself.counter == 'undefined' ) {
// It has not... perform the initialization
countMyself.counter = 0;
}
// Do something stupid to indicate the value
alert(++countMyself.counter);
}
The snippet above demonstrate "how to implement static local variable in javascript"
I know that function variables are stored in the stack. Having C background I know that variables in the stack can be easily overwritten by consequent function calls.
This doesn't seem to be the case with javascript.
What rule specifies how long a local(function) variable live in the lifetime of the program?
I mean stack in Javascript must bear different semantic than stack in C, C++?
somethingcould be?