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

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.

主站蜘蛛池模板: 兴宁市| 松滋市| 布尔津县| 成安县| 顺昌县| 太康县| 绥阳县| 万山特区| 札达县| 德格县| 贵南县| 秀山| 兰州市| 永川市| 北宁市| 离岛区| 南雄市| 庆元县| 南开区| 旺苍县| 邯郸县| 武鸣县| 长海县| 上林县| 满城县| 吉安县| 临泽县| 江山市| 泸州市| 招远市| 绵阳市| 新竹县| 五大连池市| 呼伦贝尔市| 隆安县| 蓬溪县| 中江县| 波密县| 浦县| 沂南县| 梁山县|