File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -571,16 +571,28 @@ class MyClass {}
571571
572572## Babel转码器的支持
573573
574- 目前,Babel转码器已经支持Decorator,命令行的用法如下。
574+ 目前,Babel转码器已经支持Decorator。
575+
576+ 首先,安装` babel-core ` 和` babel-plugin-transform-decorators ` 。由于后者包括在` babel-preset-stage-0 ` 之中,所以改为安装` babel-preset-stage-0 ` 亦可。
575577
576578``` bash
577- $ babel --optional es7. decorators
579+ $ npm install babel-core babel-plugin-transform- decorators
578580```
579581
582+ 然后,设置配置文件` .babelrc ` 。
583+
584+ ``` javascript
585+ {
586+ " plugins" : [" transform-decorators" ]
587+ }
588+ ```
589+
590+ 这时,Babel就可以对Decorator转码了。
591+
580592脚本中打开的命令如下。
581593
582594``` javascript
583- babel .transform (" code" , {optional : [" es7. decorators" ]})
595+ babel .transform (" code" , {plugins : [" transform- decorators" ]})
584596```
585597
586598Babel的官方网站提供一个[ 在线转码器] ( 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
689689
690690## ES6模块的转码
691691
692- 浏览器目前还不支持ES6模块,为了现在就能使用,可以将转为ES5的写法。
692+ 浏览器目前还不支持ES6模块,为了现在就能使用,可以将转为ES5的写法。除了Babel可以用来转码之外,还有以下两个方法,也可以用来转码。
693693
694694### ES6 module transpiler
695695
@@ -707,7 +707,7 @@ $ npm install -g es6-module-transpiler
707707$ compile-modules convert file1.js file2.js
708708```
709709
710- o参数可以指定转码后的文件名 。
710+ ` -o ` 参数可以指定转码后的文件名 。
711711
712712``` bash
713713$ 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提供的方法不是很多,有些有用的方法可以自己
525525
526526### done()
527527
528- Promise对象的回调链,不管以`then`方法或`catch`方法结尾,要是最后一个方法抛出错误,都有可能无法漏掉(Promise内部的错误不会冒泡到全局 )。因此,我们可以提供一个`done`方法,总是处于回调链的尾端,保证抛出任何可能出现的错误。
528+ Promise对象的回调链,不管以`then`方法或`catch`方法结尾,要是最后一个方法抛出错误,都有可能无法捕捉到(因为Promise内部的错误不会冒泡到全局 )。因此,我们可以提供一个`done`方法,总是处于回调链的尾端,保证抛出任何可能出现的错误。
529529
530530```javascript
531531asyncFunc()
You can’t perform that action at this time.
0 commit comments