1
0
mirror of https://github.com/ruanyf/es6tutorial.git synced 2025-05-27 20:32:21 +00:00

Merge pull request #70 from lmk123/patch-5

iterator.md 中多处将 Symbol 错误的写成 System
This commit is contained in:
Ruan YiFeng 2015-07-23 21:22:22 +08:00
commit cf508c9eae

View File

@ -72,13 +72,13 @@ it.next().value // '2'
上面的例子中遍历器idMaker函数返回的指针对象并没有对应的数据结构或者说遍历器自己描述了一个数据结构出来。
在ES6中有些数据结构原生提供遍历器比如数组即不用任何处理就可以被for...of循环遍历有些就不行比如对象。原因在于这些数据结构原生部署了System.iterator属性详见下文有些没有。凡是部署了System.iterator属性的数据结构就称为部署了遍历器接口。调用这个接口就会返回一个指针对象。
在ES6中有些数据结构原生提供遍历器比如数组即不用任何处理就可以被for...of循环遍历有些就不行比如对象。原因在于这些数据结构原生部署了Symbol.iterator属性详见下文有些没有。凡是部署了Symbol.iterator属性的数据结构就称为部署了遍历器接口。调用这个接口就会返回一个指针对象。
如果使用TypeScript的写法遍历器接口Iterable、指针对象Iterator和next方法返回值的规格可以描述如下。
```javascript
interface Iterable {
[System.iterator]() : Iterator,
[Symbol.iterator]() : Iterator,
}
interface Iterator {