JavaScript: Iterator Prototype

By Xah Lee. Date: . Last updated: .

New in JS2015.

Builtin iterators of JavaScript has a prototype object.

[see 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.

JavaScript Iterable 🌟

βˆ‘ JS in Depth
XAH Β BUY NOW

JS in Depth

JS Obj Ref

DOM


JS in Depth

Basic Syntax

Value Types

Variable

String

Function

Property

Object and Inheritance

Array

Constructor/Class

Iterable 🌟

Misc