Use closure to store some private data, which is accessible by the returned function but not to the outside code.
var setup = function () { var count = 0; return function () { return (count += 1); }; }; // usage var next = setup(); next(); // returns 1 next(); // 2 next(); // 3