利用ES6的Generator语法实现自定义iterator

源代码

var fakeArray = {    _values: [1, 2, 3, 4, 5, 6],    [Symbol.iterator]() {        var _values = this._values;      var _index = 0;        var done = function(){         return _index >= _values.length;      };        var iter = {        next() {          console.log("Jerry's own iterator, current index: " + _index);          var it = {            value: _values[_index],            done: done()          };          if (!it.done) {            _index++;          }          return it;        }      };      return iter;    }  }    for (var n of fakeArray) {    console.log(n)  }

输出: