官术网_书友最值得收藏!

Module imports

ES6 also defines a module import and export interface. With the older CommonJS approach, modules are exported using the modules.export construct, and modules are imported with the require(filename) function. The ES6 approach looks a little different. In one file, define and export a class, as shown in the following code:

Class Automobile {

}
export default Automobile

And in another file, import the class, as shown in the following code:

import Automobile from ‘./classes/automobile.js’;
const myCar = new Automobile();

At present, Babel compiles ES6 modules to the same format as CommonJS modules, so you can use either the ES6 modules syntax or the CommonJS modules syntax if you’re using Babel.

主站蜘蛛池模板: 克东县| 广水市| 霍城县| 长海县| 健康| 揭阳市| 广平县| 许昌县| 景泰县| 凌海市| 大悟县| 德钦县| 宁陕县| 宝坻区| 永济市| 淮北市| 乐山市| 涿鹿县| 林西县| 汾阳市| 昌平区| 中西区| 昌图县| 海晏县| 修武县| 夏津县| 湖州市| 山阴县| 屏东市| 天峨县| 建宁县| 托里县| 张家口市| 苏尼特右旗| 同德县| 营山县| 长兴县| 额尔古纳市| 苗栗市| 镇江市| 遂宁市|