JS: Iterator (Abstract class)
What is the Keyword “Iterator”
Iterator
is the value of the property key "Iterator"
of the Global Object
.
console.log(globalThis["Iterator"] === Iterator);
Type
Type of Iterator
is a function.
console.log(typeof Iterator === "function");
Parent
Parent of Iterator
is Function.prototype.
console.log(Reflect.getPrototypeOf(Iterator) === Function.prototype);
Purpose
Has property Iterator.prototype that is the parent of all builtin Iterator, so Iterable Object can directly use methods like forEach, map, etc.
Properties
from
length
name
console.log( Reflect.ownKeys( Iterator ) ) // [ "length", "name", "prototype", "from" ] console.log( Iterator.from ) // [Function: from] console.log( Iterator.length === 0) // true console.log( Iterator.name === "Iterator") // true