Skip to content

Commit

Permalink
add some content
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanyf committed Apr 25, 2014
1 parent f68e86f commit db71d98
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ body {

#sidebar ol {
margin: 0;
padding-left: 10px;
padding-left: 30px;
padding-top: 0;
}

Expand Down
27 changes: 27 additions & 0 deletions docs/generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -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."

```
18 changes: 18 additions & 0 deletions docs/let.md
Original file line number Diff line number Diff line change
Expand Up @@ -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也用来声明变量,但是声明的是常量。一旦声明,常量的值就不能改变。
Expand Down
10 changes: 10 additions & 0 deletions docs/object.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion docs/set-map.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,4 @@ console.log(value); // undefined

```

WeakMap还有has和delete方法,但没有size方法,也无法遍历它的值。
WeakMap还有has和delete方法,但没有size方法,也无法遍历它的值,这与WeakMap的键被垃圾回收机制忽略有关
7 changes: 6 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@

// run
ditto.run();
</script>
</script>
<noscript>
<p>《ECMAScript 6入门》是一本开源的JavaScript语言教程,全面介绍ECMAScript 6新增的语法特性。</p>
<p>本书力争覆盖ES6与ES5的所有不同之处,对涉及的语法知识给予详细介绍,并给出大量简洁易懂的示例代码。</p>
<p>本书为中级难度,适合已有一定JavaScript语言基础的读者,了解这门语言的最新进展;也可当作参考手册,查寻新增的语法点。</p>
</noscript>
</body>
</html>

0 comments on commit db71d98

Please sign in to comment.