mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-24 10:22:23 +00:00
add some content
This commit is contained in:
parent
f68e86f38b
commit
db71d9829c
@ -84,7 +84,7 @@ body {
|
|||||||
|
|
||||||
#sidebar ol {
|
#sidebar ol {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding-left: 10px;
|
padding-left: 30px;
|
||||||
padding-top: 0;
|
padding-top: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,3 +151,30 @@ for (n of fibonacci()) {
|
|||||||
```
|
```
|
||||||
|
|
||||||
从上面代码可见,使用for...of语句时不需要使用next方法。
|
从上面代码可见,使用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
docs/let.md
18
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命令
|
||||||
|
|
||||||
const也用来声明变量,但是声明的是常量。一旦声明,常量的值就不能改变。
|
const也用来声明变量,但是声明的是常量。一旦声明,常量的值就不能改变。
|
||||||
|
@ -145,6 +145,16 @@ Object.defineProperty(a, mySymbol, { value: 'Hello!' });
|
|||||||
|
|
||||||
上面代码通过点结构和Object.defineProperty两种方法,为对象增加一个属性。
|
上面代码通过点结构和Object.defineProperty两种方法,为对象增加一个属性。
|
||||||
|
|
||||||
|
下面的写法为Map结构添加了一个成员,但是该成员永远无法被引用。
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
|
||||||
|
let a = Map();
|
||||||
|
a.set(Symbol(), 'Noise');
|
||||||
|
a.size // 1
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
如果要在对象内部使用symbol属性名,必须采用属性名表达式。
|
如果要在对象内部使用symbol属性名,必须采用属性名表达式。
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
@ -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/)
|
- 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)
|
- 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)
|
- 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)
|
- 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)
|
- Luke Hoban, [ES6 features](https://github.com/lukehoban/es6features)
|
||||||
|
|
||||||
|
@ -267,4 +267,4 @@ console.log(value); // undefined
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
WeakMap还有has和delete方法,但没有size方法,也无法遍历它的值。
|
WeakMap还有has和delete方法,但没有size方法,也无法遍历它的值,这与WeakMap的键被垃圾回收机制忽略有关。
|
||||||
|
@ -36,6 +36,11 @@
|
|||||||
|
|
||||||
// run
|
// run
|
||||||
ditto.run();
|
ditto.run();
|
||||||
</script>
|
</script>
|
||||||
|
<noscript>
|
||||||
|
<p>《ECMAScript 6入门》是一本开源的JavaScript语言教程,全面介绍ECMAScript 6新增的语法特性。</p>
|
||||||
|
<p>本书力争覆盖ES6与ES5的所有不同之处,对涉及的语法知识给予详细介绍,并给出大量简洁易懂的示例代码。</p>
|
||||||
|
<p>本书为中级难度,适合已有一定JavaScript语言基础的读者,了解这门语言的最新进展;也可当作参考手册,查寻新增的语法点。</p>
|
||||||
|
</noscript>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user