Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

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:

share|improve this answer

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/

share|improve this answer
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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