Skip to content

Commit

Permalink
Merge pull request ruanyf#568 from baooab/patch-2
Browse files Browse the repository at this point in the history
Fix:统一例子中的代码风格
  • Loading branch information
ruanyf authored Dec 27, 2017
2 parents e534d8b + 311cfaa commit 7b728a4
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions docs/iterator.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,13 @@ str // "hi"
`Symbol.iterator`方法的最简单实现,还是使用下一章要介绍的 Generator 函数。

```javascript
var myIterable = {};

myIterable[Symbol.iterator] = function* () {
yield 1;
yield 2;
yield 3;
};
let myIterable = {
[Symbol.iterator]: function* () {
yield 1;
yield 2;
yield 3;
}
}
[...myIterable] // [1, 2, 3]

// 或者采用下面的简洁写法
Expand All @@ -465,8 +465,8 @@ let obj = {
for (let x of obj) {
console.log(x);
}
// hello
// world
// "hello"
// "world"
```

上面代码中,`Symbol.iterator`方法几乎不用部署任何代码,只要用 yield 命令给出每一步的返回值即可。
Expand Down

0 comments on commit 7b728a4

Please sign in to comment.