Skip to content
This repository has been archived by the owner on Feb 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #24 from szchenghuang/es6-let-loops
Browse files Browse the repository at this point in the history
Replace var with let in loops.
  • Loading branch information
y2468101216 committed Nov 6, 2015
2 parents c0a98e2 + 1afbaee commit d4aebdf
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions NODE_ES6.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,17 +488,17 @@ p2
這是一個語法糖,類似 C# 裡面的 `foreach(var item in items)`

```javascript
var i1 = [1,2,3];
for(var i of i1){
let i1 = [1,2,3];
for(let i of i1){
console.log(i);
}
/*
1
2
3
*/
var i2 = 'abc';
for(var i of i2){
let i2 = 'abc';
for(let i of i2){
console.log(i);
}
/*
Expand All @@ -512,11 +512,11 @@ c

```javascript
// Generator instance
for(var i of (function*(){ yield 1; yield 2; yield 3; }())) { ... }
for(let i of (function*(){ yield 1; yield 2; yield 3; }())) { ... }
// Generic iterable
for(var i of global.__createIterableObject([1, 2, 3])) { ... }
for(let i of global.__createIterableObject([1, 2, 3])) { ... }
// Generic iterable instance
for(var i of Object.create(global.__createIterableObject([1, 2, 3]))) { ... }
for(let i of Object.create(global.__createIterableObject([1, 2, 3]))) { ... }
```

##結語
Expand Down

0 comments on commit d4aebdf

Please sign in to comment.