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:
commit
0f536b7217
@ -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
|
```javascript
|
||||||
// async 函数的写法
|
// async 函数的写法
|
||||||
@ -476,7 +476,7 @@ const res = await fetch('google.com');
|
|||||||
console.log(await res.text());
|
console.log(await res.text());
|
||||||
```
|
```
|
||||||
|
|
||||||
上面代码中,第二种写法的脚本必须使用`@std/esm`加载器,才会生效。
|
上面代码中,第二种写法的脚本必须使用`esm`加载器,才会生效。
|
||||||
|
|
||||||
## async 函数的实现原理
|
## async 函数的实现原理
|
||||||
|
|
||||||
|
@ -861,13 +861,13 @@ JavaScript 语言的对象继承是通过原型链实现的。ES6 提供了更
|
|||||||
`__proto__`属性(前后各两个下划线),用来读取或设置当前对象的`prototype`对象。目前,所有浏览器(包括 IE11)都部署了这个属性。
|
`__proto__`属性(前后各两个下划线),用来读取或设置当前对象的`prototype`对象。目前,所有浏览器(包括 IE11)都部署了这个属性。
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// es6 的写法
|
// es5 的写法
|
||||||
const obj = {
|
const obj = {
|
||||||
method: function() { ... }
|
method: function() { ... }
|
||||||
};
|
};
|
||||||
obj.__proto__ = someOtherObj;
|
obj.__proto__ = someOtherObj;
|
||||||
|
|
||||||
// es5 的写法
|
// es6 的写法
|
||||||
var obj = Object.create(someOtherObj);
|
var obj = Object.create(someOtherObj);
|
||||||
obj.method = function() { ... };
|
obj.method = function() { ... };
|
||||||
```
|
```
|
||||||
|
@ -163,13 +163,15 @@ let obj = {
|
|||||||
Symbol 类型还可以用于定义一组常量,保证这组常量的值都是不相等的。
|
Symbol 类型还可以用于定义一组常量,保证这组常量的值都是不相等的。
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
const log = {};
|
||||||
|
|
||||||
log.levels = {
|
log.levels = {
|
||||||
DEBUG: Symbol('debug'),
|
DEBUG: Symbol('debug'),
|
||||||
INFO: Symbol('info'),
|
INFO: Symbol('info'),
|
||||||
WARN: Symbol('warn')
|
WARN: Symbol('warn')
|
||||||
};
|
};
|
||||||
log(log.levels.DEBUG, 'debug message');
|
console.log(log.levels.DEBUG, 'debug message');
|
||||||
log(log.levels.INFO, 'info message');
|
console.log(log.levels.INFO, 'info message');
|
||||||
```
|
```
|
||||||
|
|
||||||
下面是另外一个例子。
|
下面是另外一个例子。
|
||||||
|
Loading…
x
Reference in New Issue
Block a user