2020-04-05

2020-06-07  本文已影响0人  八月飞花
class Iterator {
    //传入一个集合
    constructor(container) {
        this.list = container.list;
        this.index = 0;
    };
    //下一个
    next() {
        if (this.hasNext()) {
            return this.list[this.index++];
        }
    };
    //判断有没有下一个
    hasNext() {
        if (this.index >= this.list.length) {
            return false; //到头了
        }
        return true; //没到头
    };
}
| Tables        | Are           | Cool  |
| ------------- |:-------------:| -----:|
| col 3 is      | right-aligned | $1600 |
| col 2 is      | centered      |   $12 |
| zebra stripes | are neat      |    $1 |
上一篇 下一篇

猜你喜欢

热点阅读