var foo = (function(numberOfCalls) { return function() { return ++numberOfCalls; } })(0); console.log(foo());//1 console.log(foo());//2 console.log(foo());//3