Similarly, the following two modules have the same default export: //- module1.js - export default 123 These exports are distinguished by their names and are called named exports. Named exports (several per module) #Ī module can export multiple things by prefixing their declarations with the keyword export. There are two kinds of exports: named exports (several per module) and default exports (one per module). Programmatic loader API: to configure how modules are loaded and to conditionally load modules.Declarative syntax (for importing and exporting). Their support for cyclic dependencies is better than CommonJS’s.Their structure can be statically analyzed (for static checking, optimization, etc.).Their syntax is even more compact than CommonJS’s.Similar to AMD, they have direct support for asynchronous loading and configurable module loading.īeing built into the language allows ES6 modules to go beyond CommonJS and AMD (details are explained later):.Similar to CommonJS, they have a compact syntax, a preference for single exports and support for cyclic dependencies.The goal for ECMAScript 6 modules was to create a format that both users of CommonJS and of AMD are happy with: If you want more in-depth material, take a look at “ Writing Modular JavaScript With AMD, CommonJS & ES Harmony” by Addy Osmani. The above is but a grossly simplified explanation of the current state of affairs.
0 Comments
Leave a Reply. |