当前位置: 首页 > 文档资料 > Lazy.js 英文文档 >

getIterator

优质
小牛编辑
167浏览
2023-12-01

Creates an Iterator object with two methods, moveNext -- returning true or false -- and current -- returning the current value.

This method is used when asynchronously iterating over sequences. Any type inheriting from Sequence must implement this method or it can't support asynchronous iteration.

Note that this method is not intended to be used directly by application code. Rather, it is intended as a means for implementors to potentially define custom sequence types that support either synchronous or asynchronous iteration.

Signature

Sequence.getIterator = function() { /*...*/ }
Sequence.getIterator = function getIterator() {
  return new Iterator(this);
}
NameType(s)Description
returnsIterator

An iterator object.

Examples

var iterator = Lazy([1, 2]).getIterator();

iterator.moveNext(); // => true
iterator.current();  // => 1
iterator.moveNext(); // => true
iterator.current();  // => 2
iterator.moveNext(); // => false