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:
commit
cf508c9eae
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user