一、迭代器介绍迭代器(iterator)是一种接口,为各种数据结构提供统一的访问机制。只要部署了迭代器接口,任何数据结构都可以完成遍历操作。ES6新增了for...of循环的遍历命令,迭代器接口主要是for...of用迭代器接口使用原生数据(可以用forof遍历)ArrayArrgumentsSetMapStringTypedArrayNodeList原理(1)创建指针对象,指向当前数据结构的起始位置(2)第一次调用对象的next方法,指针自动指向数据结构的第一个成员(3)连续调用next方法,指针向后移动,直到指向最后一个成员(4)每次调用next方法返回一个包含value和done属性的对象2.constrng=['letme','mlxg','xiaohu'的简单实现','uzi','ming'];letiterator=rng[Symbol.iterator]();console.log(iterator.next());console.log(iterator.next());console.log(iterator.next());console.log(迭代器.next());console.log(iterator.next());console.log(iterator.next());3.Instance//声明一个对象constnewRng={name:"RoyalFamily",member:['letme','mlxg','uzi','ming',]],[Symbol.iterator](){letindex=0让那个=这个;return{next:function(){if(index
