demo/generators.js
function iterateElements(array) {
  var index = 0;
  var rv = {};
  rv[Symbol.iterator] = {
      next() {
        if (index < array.length)
          return {value: array[index++], done: false};
        return {done: true};
      }
    }
  }
function iterateElements(array) {
  var index = 0;
  var rv = {};
  rv[Symbol.iterator] = {
      next() {
        if (index < array.length)
          return {value: array[index++], done: false};
        return {done: true};
      }
    }
  }
Example 1. Writing an iterator over an array