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

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.

主站蜘蛛池模板: 务川| 涞水县| 阿拉善盟| 苗栗市| 奉化市| 大石桥市| 胶州市| 秀山| 海原县| 娱乐| 三河市| 永兴县| 阳东县| 罗定市| 京山县| 永兴县| 巴东县| 青岛市| 平谷区| 扶风县| 灵川县| 焦作市| 浑源县| 宝丰县| 扶余县| 洛浦县| 钦州市| 容城县| 洪江市| 松江区| 军事| 炉霍县| 曲阜市| 东乡县| 忻州市| 澄城县| 莲花县| 福海县| 金川县| 金山区| 鹤峰县|