How can I create static variables in Javascript?
You do it through an IIFE (immediately invoked function expression):
var incr = (function () { var i = 1; return function () { return i++; } })(); incr(); // returns 1 incr(); // returns 2