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

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.

主站蜘蛛池模板: 三河市| 台中县| 淳化县| 邵武市| 蒙自县| 仁怀市| 崇州市| 凌云县| 卓尼县| 布拖县| 芜湖市| 清徐县| 眉山市| 新营市| 乐安县| 九龙城区| 定西市| 色达县| 五原县| 双桥区| 桦川县| 赤水市| 新乐市| 明溪县| 鄯善县| 铜陵市| 壶关县| 建水县| 汪清县| 桃江县| 泾阳县| 精河县| 孝感市| 剑阁县| 南江县| 姚安县| 江油市| 江孜县| 略阳县| 聂荣县| 南溪县|