From db71d9829cd064d35a66158d28512eb11f26b4b1 Mon Sep 17 00:00:00 2001 From: ruanyf Date: Fri, 25 Apr 2014 20:36:00 +0800 Subject: [PATCH] add some content --- css/app.css | 2 +- docs/generator.md | 27 +++++++++++++++++++++++++++ docs/let.md | 18 ++++++++++++++++++ docs/object.md | 10 ++++++++++ docs/reference.md | 1 + docs/set-map.md | 2 +- index.html | 7 ++++++- 7 files changed, 64 insertions(+), 3 deletions(-) diff --git a/css/app.css b/css/app.css index 95c8c2c..ad392e2 100644 --- a/css/app.css +++ b/css/app.css @@ -84,7 +84,7 @@ body { #sidebar ol { margin: 0; - padding-left: 10px; + padding-left: 30px; padding-top: 0; } diff --git a/docs/generator.md b/docs/generator.md index 0a1ebaf..c44ab71 100644 --- a/docs/generator.md +++ b/docs/generator.md @@ -151,3 +151,30 @@ for (n of fibonacci()) { ``` 从上面代码可见,使用for...of语句时不需要使用next方法。 + +## yield*语句 + +如果yield命令后面跟的是一个遍历器,需要在yield命令后面加上星号,表明它返回的是一个遍历器。这被称为yield*语句。 + +```javascript + +let delegatedIterator = (function* () { + yield 'Hello!'; + yield 'Bye!'; +}()); + +let delegatingIterator = (function* () { + yield 'Greetings!'; + yield* delegatedIterator; + yield 'Ok, bye.'; +}()); + +for(let value of delegatingIterator) { + console.log(value); +} +// "Greetings! +// "Hello!" +// "Bye!" +// "Ok, bye." + +``` diff --git a/docs/let.md b/docs/let.md index 0d83695..bbb2236 100644 --- a/docs/let.md +++ b/docs/let.md @@ -102,6 +102,24 @@ function f1() { ``` +另外,ES6的函数也默认在块级作用域内声明。 + +```javascript + +function f() { console.log('I am outside!'); } +(function () { + if(false) { + // What should happen with this redeclaration? + function f() { console.log('I am inside!'); } + } + + f(); +}()); + +``` + +上面代码在ES5中运行,会得到“I am inside!”,但是在ES6中运行,会得到“I am outside!”。 + ## const命令 const也用来声明变量,但是声明的是常量。一旦声明,常量的值就不能改变。 diff --git a/docs/object.md b/docs/object.md index dd5ce9a..7d6da97 100644 --- a/docs/object.md +++ b/docs/object.md @@ -145,6 +145,16 @@ Object.defineProperty(a, mySymbol, { value: 'Hello!' }); 上面代码通过点结构和Object.defineProperty两种方法,为对象增加一个属性。 +下面的写法为Map结构添加了一个成员,但是该成员永远无法被引用。 + +```javascript + +let a = Map(); +a.set(Symbol(), 'Noise'); +a.size // 1 + +``` + 如果要在对象内部使用symbol属性名,必须采用属性名表达式。 ```javascript diff --git a/docs/reference.md b/docs/reference.md index 20012ea..8d3ea85 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -7,6 +7,7 @@ - Dale Schouten, [10 Ecmascript-6 tricks you can perform right now](http://html5hub.com/10-ecmascript-6-tricks-you-can-perform-right-now/) - 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) - Ryan Dao, [Summary of ECMAScript 6 major features](http://ryandao.net/portal/content/summary-ecmascript-6-major-features) - Luke Hoban, [ES6 features](https://github.com/lukehoban/es6features) diff --git a/docs/set-map.md b/docs/set-map.md index 3c4a5f3..26f1ad4 100644 --- a/docs/set-map.md +++ b/docs/set-map.md @@ -267,4 +267,4 @@ console.log(value); // undefined ``` -WeakMap还有has和delete方法,但没有size方法,也无法遍历它的值。 +WeakMap还有has和delete方法,但没有size方法,也无法遍历它的值,这与WeakMap的键被垃圾回收机制忽略有关。 diff --git a/index.html b/index.html index 45c990b..78eede2 100644 --- a/index.html +++ b/index.html @@ -36,6 +36,11 @@ // run ditto.run(); - + +