function foo() { this.result = this.result || 0; return this.result++; } alert([foo(), foo(), foo()]);