Skip to content

Commit 7b728a4

Browse files
authored
Merge pull request ruanyf#568 from baooab/patch-2
Fix:统一例子中的代码风格
2 parents e534d8b + 311cfaa commit 7b728a4

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

docs/iterator.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,13 @@ str // "hi"
444444
`Symbol.iterator`方法的最简单实现,还是使用下一章要介绍的 Generator 函数。
445445

446446
```javascript
447-
var myIterable = {};
448-
449-
myIterable[Symbol.iterator] = function* () {
450-
yield 1;
451-
yield 2;
452-
yield 3;
453-
};
447+
let myIterable = {
448+
[Symbol.iterator]: function* () {
449+
yield 1;
450+
yield 2;
451+
yield 3;
452+
}
453+
}
454454
[...myIterable] // [1, 2, 3]
455455

456456
// 或者采用下面的简洁写法
@@ -465,8 +465,8 @@ let obj = {
465465
for (let x of obj) {
466466
console.log(x);
467467
}
468-
// hello
469-
// world
468+
// "hello"
469+
// "world"
470470
```
471471

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

0 commit comments

Comments
 (0)