7

Generators are being introduced in the new version of the ECMA standards. Could any one suggest the importance and the usage of generators in the present Javascript world? Examples of generators in real world problems will be helpful.

asked May 14, 2012 at 14:33

2 Answers 2

3

Starters

I'd suggest to look at:

A simple example is given in the Mozilla Developer Doc introducing the new features of JavaScript 1.7:

function fib() {
 var i = 0, j = 1;
 while (true) {
 yield i;
 var t = i;
 i = j;
 j += t;
 }
}
var g = fib();
for (var i = 0; i < 10; i++) {
 console.log(g.next());
}

Others are available in the documents listed above.

Real-World

For real world examples, you can for instance see:

answered Jun 6, 2012 at 18:32
0

I think Generators are best explained in the following article: https://developer.mozilla.org/en/JavaScript/Guide/Iterators_and_Generators

This might be also useful: http://ejohn.org/blog/javascript-18-progress/

answered May 15, 2012 at 12:24
1
  • 3
    This doesn't answer the question. Posting links is best left to comments, unless you're going to expand on the contents of the linked page. Commented May 15, 2012 at 13:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.