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.

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:

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/

  • 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. – zzzzBov May 15 '12 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.