1
0
mirror of https://github.com/ruanyf/es6tutorial.git synced 2025-05-28 21:32:20 +00:00

Merge branch 'gh-pages' of github.com:ruanyf/es6tutorial into gh-pages

This commit is contained in:
ruanyf 2018-06-04 11:13:17 +08:00
commit 0f536b7217
3 changed files with 8 additions and 6 deletions

View File

@ -460,7 +460,7 @@ async function dbFuc(db) {
}
```
目前,[`@std/esm`](https://www.npmjs.com/package/@std/esm)模块加载器支持顶层`await`,即`await`命令可以不放在 async 函数里面,直接使用。
目前,[`esm`](https://www.npmjs.com/package/esm)模块加载器支持顶层`await`,即`await`命令可以不放在 async 函数里面,直接使用。
```javascript
// async 函数的写法
@ -476,7 +476,7 @@ const res = await fetch('google.com');
console.log(await res.text());
```
上面代码中,第二种写法的脚本必须使用`@std/esm`加载器,才会生效。
上面代码中,第二种写法的脚本必须使用`esm`加载器,才会生效。
## async 函数的实现原理

View File

@ -861,13 +861,13 @@ JavaScript 语言的对象继承是通过原型链实现的。ES6 提供了更
`__proto__`属性(前后各两个下划线),用来读取或设置当前对象的`prototype`对象。目前,所有浏览器(包括 IE11都部署了这个属性。
```javascript
// es6 的写法
// es5 的写法
const obj = {
method: function() { ... }
};
obj.__proto__ = someOtherObj;
// es5 的写法
// es6 的写法
var obj = Object.create(someOtherObj);
obj.method = function() { ... };
```

View File

@ -163,13 +163,15 @@ let obj = {
Symbol 类型还可以用于定义一组常量,保证这组常量的值都是不相等的。
```javascript
const log = {};
log.levels = {
DEBUG: Symbol('debug'),
INFO: Symbol('info'),
WARN: Symbol('warn')
};
log(log.levels.DEBUG, 'debug message');
log(log.levels.INFO, 'info message');
console.log(log.levels.DEBUG, 'debug message');
console.log(log.levels.INFO, 'info message');
```
下面是另外一个例子。