JS: Iterator Interface
Object having Iterator Interface is called Iterator. Iterator is used as function to general next values.
Iterator Interface Properties
"next"
-
- Value must be a function.
- This function's return value must be an object that has IteratorResult Interface.
- If a previous call to the
next
method of an Iterator has returned an IteratorResult object whosedone
property istrue
, then all subsequent calls to thenext
method of that object should also return an IteratorResult object whosedone
property istrue
. However, this requirement is not enforced.
Iterator Interface Optional Property Keys
The following are optional
"return"
-
- Value must be a function.
- This function's return value must be an object that has IteratorResult Interface.
- Invoking this method notifies the Iterator object that the caller does not intend to make any more
next
method calls to the Iterator. - The returned IteratorResult object will typically have a
done
property whose value istrue
, and a value property with the value passed as the argument of the return method. However, this requirement is not enforced.
"throw"
-
- Value must be a function.
- This function's return value must be an object that has IteratorResult Interface.
- Invoking this method notifies the Iterator object that the caller has detected an error condition.
- The argument may be used to identify the error condition and typically will be an exception object.
- A typical response is to throw the value passed as the argument.
- If the method does not throw, the returned IteratorResult object will typically have a
done
property whose value istrue
.