Iterator(遍历器) ES6
来源:互联网 发布:怎么在淘宝上搜店铺号 编辑:程序博客网 时间:2024/06/05 18:58
Iterator的作用有三个:一是为各种数据结构,提供一个统一的、简便的访问接口;二是使得数据结构的成员能够按某种次序排列;三是ES6创造了一 种新的遍历命令for...of
循环,Iterator接口主要供 for...of
消费。
Iterator的遍历过程是这样的。
(1)创建一个指针对象,指向当前数据结构的起始位置。也就是说,遍历器对象本质上,就是一个指针对象。
(2)第一次调用指针对象的 next方法,可以将指针指向数据结构的第一个成员。
(3)第二次调用指针对象的 next方法,指针就指向数据结构的第二个成员。
(4)不断调用指针对象的 next方法,直到它指向数据结构的结束位置。
下面是模仿next返回值的例子:
var it = makeIterator(['a', 'b']);it.next() // { value: "a", done: false } it.next() // { value: "b", done: false } it.next() // { value: undefined, done: true }function makeIterator(array) { var nextIndex = 0;return { next: function() { return nextIndex < array.length ? {value: array[nextIndex++], done: false} : {value: undefined, done: true}; } }; }
0 0
- Iterator(遍历器) ES6
- ES6 Iterator遍历器
- ES6 -- 遍历器Iterator和for...of
- 探索ES6 Iterator(遍历器)
- ES6——Iterator(遍历器)
- ES6(二) Iterator(遍历器)和for-of循环
- 13、ES6 Iterator(遍历器)的概念
- ES6-Iterator与for..of..遍历
- 【ES6学习】— (7)Set、Map数据结构与Iterator遍历器
- es6 itaertor遍历器
- es6 iterator(十四)
- 【ES6】Iterator和Generator
- ES6学习笔记:Iterator
- Iterator遍历
- Iterator遍历
- Iterator遍历
- ES6之字符串的遍历器接口
- 浅析Java遍历器(Iterator)的实现
- bzoj 2618: [Cqoi2006]凸多边形 (半平面交)
- iOS iTunes connect提交审核invalid binary或构建版本没有显示
- 【Spring+MyBatis+MySQL实战入门】二、MyBatis和MyBatis Generator的配置
- memcache 常见题
- XML解析的三种方式
- Iterator(遍历器) ES6
- POJ 2586
- https访问公钥问题
- lua math库(备忘)
- HttpClient抓取【需登录跳转页面】的数据
- link js重构心得
- 深入理解LINUX下动态库链接器/加载器ld-linux.so.2
- 说说 JavaScript Object 类型
- web前端工作规范指导