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

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.

主站蜘蛛池模板: 美姑县| 横峰县| 灵石县| 黄大仙区| 炉霍县| 积石山| 宁明县| 砀山县| 云和县| 荥经县| 隆尧县| 外汇| 拜泉县| 全南县| 三台县| 盘锦市| 江陵县| 青川县| 怀来县| 阳高县| 全州县| 陕西省| 厦门市| 平原县| 广平县| 天全县| 寿阳县| 霍州市| 弥渡县| 平陆县| 澳门| 绥化市| 六枝特区| 中方县| 灵宝市| 静海县| 即墨市| 耿马| 伊川县| 南投县| 鄂尔多斯市|