Tip 47 Isolate Functionality with Import and Export

In this tip, you’ll learn how to share code between files.

In the bad old days of JavaScript, you kept all code in a single file. Even worse, developers would put all their JavaScript code in the DOM under a single <script> tag.

Things got better slowly. First, someone created code to minify and concatenate files so at least you had only one small import statement. Then projects such as Require.js and CommonJS gave developers a way to share code between files using modules. With the module system, JavaScript developers were finally able to easily reuse code in a project.

Modules have been simplified and are now simple import and export statements. And with this simple interface, not only ...

Get Simplifying JavaScript now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.