function foo() { var i = 0; foo = function() { return ['Hello', 'World'][i++]; } return foo() } alert([foo(), foo()].join(' '));