🔸make-iterator method

JSiterationiterable ⟩ make-iterator method

an iterable must implement a special method named [Symbol.iterator], which returns an iterator.

class A {
    // ⭐️ "make-iterator" method
    // make an iterator by using generator function.
    *[Symbol.iterator]() { yield 1; yield 2; }
}

we can implement the make-iterator method by:

similar to .makeIterator() method of Sequence protocol in Swift

By default, using array[Symbol.iterator] will return the values() function.

do NOT use @@iterator as the method name, it's just a "specification" thing❗️

Last updated