“I think what we focused on in [upgrading] the core platform,” Schroepfer said, “was, how do we put the right core primitives in the main platform to make Firefox both a great development platform and a great platform for end users to use, and then how do we leverage the extensibility of that platform through extensions to let developers effectively write their own tools that they need to write, in order to build these vast, distributed Web-based applications?”
With generators and iterators instead, a variable can be declared and assigned the function containing the reiterative loop as its “value.” Here, the variable acts more like an object. The loop clause that counts the first numbers in the sequence exists outside the function, so the main body of the program has control over how many times the function is entered.
Execution steps into the function for one round — one iteration — by means of the .next method, which acts as the iterator. The function “knows” it’s being used for multiple iterations, even though it doesn’t maintain the loop. It gracefully passes execution back to the main body, which has the loop, by means of the all-new yield statement. This is the generator.
BetaNews will feature more with Mike Schroepfer and more of the new under-the-hood features of Firefox 2.0 as its release approaches.