May 2018
Beginner to intermediate
356 pages
9h 25m
English
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.
Read now
Unlock full access