How can I create static variables in Javascript?
The closest thing in JavaScript to a static variable is a global variable - this is simply a variable declared outside the scope of a function or object literal:
var thisIsGlobal = 1;
function foo() {
var thisIsNot = 2;
}
The other thing you could do would be to store global variables inside an object literal like this:
var foo = { bar : 1 }
And then access the variabels like this: foo.bar
.