Javascript STATIC VARIABLE?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • john_doe9

    Javascript STATIC VARIABLE?

    is there a way to declare static variable in a function like so?

    function foo(){
    static count;

    count++;
    }

    Thank you.
  • RobB

    #2
    Re: Javascript STATIC VARIABLE?

    john_doe9 wrote:[color=blue]
    > is there a way to declare static variable in a function like so?
    >
    > function foo(){
    > static count;
    >
    > count++;
    > }
    >
    > Thank you.[/color]

    function foo()
    {
    foo.count = ++foo.count || 1;
    alert(foo.count );
    }

    Comment

    Working...