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

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.

主站蜘蛛池模板: 文登市| 青州市| 建德市| 辰溪县| 红河县| 罗甸县| 涿州市| 左贡县| 临城县| 青州市| 航空| 山阴县| 南丹县| 平乐县| 丹棱县| 若尔盖县| 枣强县| 柏乡县| 电白县| 徐水县| 西昌市| 望城县| 武川县| 开阳县| 安国市| 阳泉市| 上犹县| 师宗县| 金昌市| 密云县| 西平县| 开化县| 密云县| 喀喇| 阳江市| 墨竹工卡县| 海阳市| 安徽省| 泽普县| 炉霍县| 达日县|