Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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++) {

Others are available in the documents listed above.


For real world examples, you can for instance see:

share|improve this answer

I think Generators are best explained in the following article:

This might be also useful:

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