JS: Iterator Prototype

By Xah Lee. Date: . Last updated: .

New in ES2015.

Builtin iterators of JavaScript has a prototype object.

[see JS: Iterator]

The Iterator Prototype object is denoted as “%IteratorPrototype%” by the JavaScript spec.

There's no direct syntax for it. But you can get it by

Reflect.getPrototypeOf ( Reflect.getPrototypeOf ( Object([][Symbol.iterator]) ))

// iterator's proprotype
const itrp = Reflect.getPrototypeOf ( Reflect.getPrototypeOf ( Object([][Symbol.iterator]) )) ;

// add a property
itrp.x = 3;

// inherited by all iterators
console.log ( [][Symbol.iterator].x );
// 3

You can add properties to this iterator prototype, so all builtin iterators will inherit it.

JS Iterable ⭐

  1. Interface
  2. Iterable
  3. Iterator
  4. Iterator Prototype
  5. for-of Loop
  6. Spread Operator
  7. Generator
  8. Generator Function
Like it? Help me by telling your friends. Or, Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials