mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-25 11:12:21 +00:00
fix typo
This commit is contained in:
parent
1ed8d1d915
commit
85f0cfeb3f
@ -571,16 +571,28 @@ class MyClass {}
|
|||||||
|
|
||||||
## Babel转码器的支持
|
## Babel转码器的支持
|
||||||
|
|
||||||
目前,Babel转码器已经支持Decorator,命令行的用法如下。
|
目前,Babel转码器已经支持Decorator。
|
||||||
|
|
||||||
|
首先,安装`babel-core`和`babel-plugin-transform-decorators`。由于后者包括在`babel-preset-stage-0`之中,所以改为安装`babel-preset-stage-0`亦可。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ babel --optional es7.decorators
|
$ npm install babel-core babel-plugin-transform-decorators
|
||||||
```
|
```
|
||||||
|
|
||||||
|
然后,设置配置文件`.babelrc`。
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
{
|
||||||
|
"plugins": ["transform-decorators"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
这时,Babel就可以对Decorator转码了。
|
||||||
|
|
||||||
脚本中打开的命令如下。
|
脚本中打开的命令如下。
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
babel.transform("code", {optional: ["es7.decorators"]})
|
babel.transform("code", {plugins: ["transform-decorators"]})
|
||||||
```
|
```
|
||||||
|
|
||||||
Babel的官方网站提供一个[在线转码器](https://babeljs.io/repl/),只要勾选Experimental,就能支持Decorator的在线转码。
|
Babel的官方网站提供一个[在线转码器](https://babeljs.io/repl/),只要勾选Experimental,就能支持Decorator的在线转码。
|
||||||
|
@ -689,7 +689,7 @@ TypeError: even is not a function
|
|||||||
|
|
||||||
## ES6模块的转码
|
## ES6模块的转码
|
||||||
|
|
||||||
浏览器目前还不支持ES6模块,为了现在就能使用,可以将转为ES5的写法。
|
浏览器目前还不支持ES6模块,为了现在就能使用,可以将转为ES5的写法。除了Babel可以用来转码之外,还有以下两个方法,也可以用来转码。
|
||||||
|
|
||||||
### ES6 module transpiler
|
### ES6 module transpiler
|
||||||
|
|
||||||
@ -707,7 +707,7 @@ $ npm install -g es6-module-transpiler
|
|||||||
$ compile-modules convert file1.js file2.js
|
$ compile-modules convert file1.js file2.js
|
||||||
```
|
```
|
||||||
|
|
||||||
o参数可以指定转码后的文件名。
|
`-o`参数可以指定转码后的文件名。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ compile-modules convert -o out.js file1.js
|
$ compile-modules convert -o out.js file1.js
|
||||||
|
@ -525,7 +525,7 @@ ES6的Promise API提供的方法不是很多,有些有用的方法可以自己
|
|||||||
|
|
||||||
### done()
|
### done()
|
||||||
|
|
||||||
Promise对象的回调链,不管以`then`方法或`catch`方法结尾,要是最后一个方法抛出错误,都有可能无法漏掉(Promise内部的错误不会冒泡到全局)。因此,我们可以提供一个`done`方法,总是处于回调链的尾端,保证抛出任何可能出现的错误。
|
Promise对象的回调链,不管以`then`方法或`catch`方法结尾,要是最后一个方法抛出错误,都有可能无法捕捉到(因为Promise内部的错误不会冒泡到全局)。因此,我们可以提供一个`done`方法,总是处于回调链的尾端,保证抛出任何可能出现的错误。
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
asyncFunc()
|
asyncFunc()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user