One of the new mechanisms available in JavaScript 1.7 is yield, useful for generators and iterators.
This is currently supported in Mozilla browsers only (that I’m aware of). What are some of the ways to simulate this behavior in browsers where it is not available?
Well you could always write an outer function that initializes variables in a closure and then returns an object that does whatever work you want.
Now you can write:
and then call
gen.next()over and over again. It’d be tricky to simulate the “finally” behavior of the “close()” method on real generators, but you might be able to get somewhere close.