💾IteratorPrototype

JSiterationiterator ⟩ IteratorPrototype

💾 replit:IteratorPrototype

// ⭐ %IteratorPrototype%
// -------------------------------------------------------
//   prototype of all built-in iterators
//
//   const IteratorPrototype = {
//       [Symbol.iterator]() { return this },
//   };
//
// Note: 
//   in ECMAScript spec, internal objects are enclosed
//   in percent (%) signs.

// ⭐ %IteratorPrototype% is not directly accessible, 
//    but we can access it indirectly (from any built-in iterator).
//
// ⭐ array iterator -> ArrayIterator -> IteratorPrototype
const IteratorPrototype = Object.getPrototypeOf(    // IteratorPrototype
    Object.getPrototypeOf(                          // ArrayIterator
        [][Symbol.iterator]()    // ⭐ let empty array make an iterator
    )
);

💈範例:

Last updated

Was this helpful?