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 conforms to the IteratorResult Interface.
- If a previous call to the
nextmethod of an Iterator has returned an IteratorResult object whosedoneproperty istrue, then all subsequent calls to thenextmethod of that object should also return an IteratorResult object whosedoneproperty 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 conforms to the IteratorResult Interface.
- Invoking this method notifies the Iterator object that the caller does not intend to make any more
nextmethod calls to the Iterator. - The returned IteratorResult object will typically have a
doneproperty 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 conforms to the 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
doneproperty whose value istrue.