Javascript-迭代器混乱

In this simple code, the console.log(names.next().value); if called twice the array index increases. I'm not sure how its doing that since I think it should always start with 0 so it should have returned the same value.

有人可以解释它是如何做到的吗?

// Iterator Example
function nameIterator(names) {
  let nextIndex = 0;
  console.log(nextIndex);

  return {
    next: function() {
      return nextIndex < names.length ? {
        value: names[nextIndex++],
        done: false
      } : {
        done: true
      }
    }
  }
}

// Create an array of names
const namesArr = ['Brad', 'Sara', 'John'];
// Init iterator and pass in the names array
const names = nameIterator(namesArr);

console.log(names.next().value);
console.log(names.next().value);
console.log(names.next().value);
console.log(names.next());

输出:

Brad
Sara
John
Object : {done: true}