mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-24 18:32:22 +00:00
修订错误
This commit is contained in:
parent
cb9bccc2a6
commit
e9ff296338
@ -105,7 +105,7 @@ loadUI.next()
|
||||
|
||||
```
|
||||
|
||||
上面代码表示,第一次调用loadUI函数时,该函数不会执行,仅返回一个遍历器。下一次对该遍历器调用next方法,则会显示登录窗口,并且异步加载数据。再一次使用next方法,则会隐藏登录窗口。可以看到,这种写法的好处是所有登录窗口的逻辑,都被封装在一个函数,按部就班非常清晰。
|
||||
上面代码表示,第一次调用loadUI函数时,该函数不会执行,仅返回一个遍历器。下一次对该遍历器调用next方法,则会显示登录界面,并且异步加载数据。再一次使用next方法,则会隐藏登录界面。可以看到,这种写法的好处是所有登录界面的逻辑,都被封装在一个函数,按部就班非常清晰。
|
||||
|
||||
注意,yield语句是同步运行,不是异步运行(否则就失去了取代回调函数的设计目的了)。实际操作中,一般让yield语句返回Promises对象。
|
||||
|
||||
|
@ -50,13 +50,25 @@ node --harmony
|
||||
|
||||
```
|
||||
|
||||
启动命令中的`--harmony`选项可以打开大部分的ES6功能,但是还有一些特性,需要单独打开,主要是使用`--use_strict`选项打开块级作用域功能、使用`--harmony_generators`选项打开generator功能。
|
||||
|
||||
使用下面的命令,可以查看所有与ES6有关的选项。
|
||||
启动命令中的`--harmony`选项可以打开所有已经部署的ES6功能。使用下面的命令,可以查看所有与ES6有关的单个选项。
|
||||
|
||||
```bash
|
||||
|
||||
node --v8-options | grep harmony
|
||||
$ node --v8-options | grep harmony
|
||||
--harmony_typeof (enable harmony semantics for typeof)
|
||||
--harmony_scoping (enable harmony block scoping)
|
||||
--harmony_modules (enable harmony modules (implies block scoping))
|
||||
--harmony_symbols (enable harmony symbols (a.k.a. private names))
|
||||
--harmony_proxies (enable harmony proxies)
|
||||
--harmony_collections (enable harmony collections (sets, maps, and weak maps))
|
||||
--harmony_observation (enable harmony object observation (implies harmony collections)
|
||||
--harmony_generators (enable harmony generators)
|
||||
--harmony_iteration (enable harmony iteration (for-of))
|
||||
--harmony_numeric_literals (enable harmony numeric literals (0o77, 0b11))
|
||||
--harmony_strings (enable harmony string)
|
||||
--harmony_arrays (enable harmony arrays)
|
||||
--harmony_maths (enable harmony math functions)
|
||||
--harmony (enable all harmony features (except typeof))
|
||||
|
||||
```
|
||||
|
||||
|
@ -84,7 +84,7 @@ function f1() {
|
||||
|
||||
上面的函数有两个代码块,都声明了变量n,运行后输出5。这表示外层代码块不受内层代码块的影响。如果使用var定义变量n,最后输出的值就是10。
|
||||
|
||||
块级作用域的出现,实际上使得获得广泛应用的立即执行函数(IIFE)不再必要了。
|
||||
块级作用域的出现,实际上使得获得广泛应用的立即执行匿名函数(IIFE)不再必要了。
|
||||
|
||||
```javascript
|
||||
|
||||
@ -102,14 +102,14 @@ function f1() {
|
||||
|
||||
```
|
||||
|
||||
另外,ES6的函数也默认在块级作用域内声明。
|
||||
另外,ES6也规定,函数的作用域为其所在的块级作用域。
|
||||
|
||||
```javascript
|
||||
|
||||
function f() { console.log('I am outside!'); }
|
||||
(function () {
|
||||
if(false) {
|
||||
// What should happen with this redeclaration?
|
||||
// 重复声明一次函数f
|
||||
function f() { console.log('I am inside!'); }
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user