File tree Expand file tree Collapse file tree 3 files changed +18
-6
lines changed Expand file tree Collapse file tree 3 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -571,16 +571,28 @@ class MyClass {}
571
571
572
572
## Babel转码器的支持
573
573
574
- 目前,Babel转码器已经支持Decorator,命令行的用法如下。
574
+ 目前,Babel转码器已经支持Decorator。
575
+
576
+ 首先,安装` babel-core ` 和` babel-plugin-transform-decorators ` 。由于后者包括在` babel-preset-stage-0 ` 之中,所以改为安装` babel-preset-stage-0 ` 亦可。
575
577
576
578
``` bash
577
- $ babel --optional es7. decorators
579
+ $ npm install babel-core babel-plugin-transform- decorators
578
580
```
579
581
582
+ 然后,设置配置文件` .babelrc ` 。
583
+
584
+ ``` javascript
585
+ {
586
+ " plugins" : [" transform-decorators" ]
587
+ }
588
+ ```
589
+
590
+ 这时,Babel就可以对Decorator转码了。
591
+
580
592
脚本中打开的命令如下。
581
593
582
594
``` javascript
583
- babel .transform (" code" , {optional : [" es7. decorators" ]})
595
+ babel .transform (" code" , {plugins : [" transform- decorators" ]})
584
596
```
585
597
586
598
Babel的官方网站提供一个[ 在线转码器] ( https://babeljs.io/repl/ ) ,只要勾选Experimental,就能支持Decorator的在线转码。
Original file line number Diff line number Diff line change @@ -689,7 +689,7 @@ TypeError: even is not a function
689
689
690
690
## ES6模块的转码
691
691
692
- 浏览器目前还不支持ES6模块,为了现在就能使用,可以将转为ES5的写法。
692
+ 浏览器目前还不支持ES6模块,为了现在就能使用,可以将转为ES5的写法。除了Babel可以用来转码之外,还有以下两个方法,也可以用来转码。
693
693
694
694
### ES6 module transpiler
695
695
@@ -707,7 +707,7 @@ $ npm install -g es6-module-transpiler
707
707
$ compile-modules convert file1.js file2.js
708
708
```
709
709
710
- o参数可以指定转码后的文件名 。
710
+ ` -o ` 参数可以指定转码后的文件名 。
711
711
712
712
``` bash
713
713
$ compile-modules convert -o out.js file1.js
Original file line number Diff line number Diff line change @@ -525,7 +525,7 @@ ES6的Promise API提供的方法不是很多,有些有用的方法可以自己
525
525
526
526
### done()
527
527
528
- Promise对象的回调链,不管以`then`方法或`catch`方法结尾,要是最后一个方法抛出错误,都有可能无法漏掉(Promise内部的错误不会冒泡到全局 )。因此,我们可以提供一个`done`方法,总是处于回调链的尾端,保证抛出任何可能出现的错误。
528
+ Promise对象的回调链,不管以`then`方法或`catch`方法结尾,要是最后一个方法抛出错误,都有可能无法捕捉到(因为Promise内部的错误不会冒泡到全局 )。因此,我们可以提供一个`done`方法,总是处于回调链的尾端,保证抛出任何可能出现的错误。
529
529
530
530
```javascript
531
531
asyncFunc()
You can’t perform that action at this time.
0 commit comments