Click to See Complete Forum and Search --> : C-like static internal variable


sergiodegioia
11-20-2003, 08:24 AM
what's in the Javascript language the correspondent of a C declaration like:
void foo_function{

static int foo; //in a function scope, meaning an internal
//variable whose value is left unchanged
//between two consecutive function calls
...
}

Any use has to, or alternatively can, be made of the class construct

gil davis
11-20-2003, 09:28 AM
When you create a VAR in a function, it has a local scope, and does not exist outside the function. However, it can be changed inside the function. Since JavaScript is an interpretive language, concepts like "static" would not mean much because everything is dynamic by design.

sergiodegioia
11-20-2003, 10:29 AM
what I mean is: is it possible to have a local variable whose life outlasts function scope, though being not accessible outside it, and whose value when the function terminated can be resumed at the next function call? that is, just like C static internal variable. Here static has nothing to do with "dynamicity" of variables or that C programs are to compile to get them run

gil davis
11-20-2003, 10:34 AM
No. Things declared as VAR inside a function live only for the duration of the function. If you want it to persist, you will have to make it global.