JS: Iterator.prototype

By Xah Lee. Date: . Last updated: .

What is Iterator.prototype

Iterator.prototype is the value of the property key "prototype" of the function Iterator. 〔see Iterator Object

console.log(Iterator.hasOwnProperty("prototype"));

Type

Type of Iterator.prototype is Object .

console.log(typeof Iterator.prototype === "object");

Parent

Parent of Iterator.prototype is Object.prototype .

// parent of Iterator.prototype
console.log(Reflect.getPrototypeOf(Iterator.prototype) === Object.prototype);

Purpose

Allow all standard Iterable objects to have methods such as map, forEach, filter, etc, without having to convert to array first. Similarly, modify given Iterator to return a new iterator.

Properties

constructor

value is Iterator

console.log(Iterator.prototype.constructor === Iterator);
// true

xtodo

JavaScript. Iterable, Iterator