mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2024-04-21 12:32:22 +00:00
修改let
This commit is contained in:
+1
-1
@@ -412,7 +412,7 @@ for(let value of delegatingIterator) {
|
||||
|
||||
```
|
||||
|
||||
上面代码中,delegatingIterator是代理者,delegatedIterator是被代理者。由于`yield* delegatedIterator`语句得到的值,是一个遍历器,所以要用星号表示。
|
||||
上面代码中,delegatingIterator是代理者,delegatedIterator是被代理者。由于`yield* delegatedIterator`语句得到的值,是一个遍历器,所以要用星号表示。运行结果就是使用一个遍历器,遍历了多个Genertor函数,有递归的效果。
|
||||
|
||||
下面是一个稍微复杂的例子,使用yield*语句遍历完全二叉树。
|
||||
|
||||
|
||||
+14
@@ -18,6 +18,20 @@ b //1
|
||||
|
||||
上面代码在代码块之中,分别用let和var声明了两个变量。然后在代码块之外调用这两个变量,结果let声明的变量报错,var声明的变量返回了正确的值。这表明,let声明的变量只在它所在的代码块有效。
|
||||
|
||||
for循环的计数器,就很合适使用let命令。
|
||||
|
||||
```javascript
|
||||
|
||||
for(let i = 0; i < arr.length; i++){}
|
||||
|
||||
console.log(i)
|
||||
//ReferenceError: i is not defined
|
||||
|
||||
|
||||
```
|
||||
|
||||
上面代码的计数器i,只在for循环体内有效。
|
||||
|
||||
下面的代码如果使用var,最后输出的是9。
|
||||
|
||||
```javascript
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
- Sayanee Basu, [Use ECMAScript 6 Today](http://net.tutsplus.com/articles/news/ecmascript-6-today/)
|
||||
- Ariya Hidayat, [Toward Modern Web Apps with ECMAScript 6](http://www.sencha.com/blog/toward-modern-web-apps-with-ecmascript-6/)
|
||||
- Dale Schouten, [10 Ecmascript-6 tricks you can perform right now](http://html5hub.com/10-ecmascript-6-tricks-you-can-perform-right-now/)
|
||||
- Colin Toh, [Lightweight ES6 Features That Pack A Punch](http://colintoh.com/blog/lightweight-es6-features): ES6的一些“轻量级”的特性介绍
|
||||
- Domenic Denicola, [ES6: The Awesome Parts](http://www.slideshare.net/domenicdenicola/es6-the-awesome-parts)
|
||||
- Nicholas C. Zakas, [Understanding ECMAScript 6](https://github.com/nzakas/understandinges6)
|
||||
- Justin Drake, [ECMAScript 6 in Node.JS](https://github.com/JustinDrake/node-es6-examples)
|
||||
|
||||
Reference in New Issue
Block a user