ECMAScript Cookbook
上QQ阅读APP看书,第一时间看更新

How it works...

There are two options for exporting a member from a module. It can either be exported as the default member, or as a named member. In rocket.js, we see both methods:

export default name = "Saturn V"; 
export const COUNT_DOWN_DURATION = 10; 
export function launch () { ... } 

In this case, the string "Saturn V" is exported as the default member, while COUNT_DOWN_DURATION and launch are exported as named members. We can see the effect this has had when importing the module in main.js:

 import rocketName, { launch, COUNT_DOWN_DURATION } from './rocket.js'; 

We can see the difference in how the default member and the name members are imported. The name members appear inside the curly braces, and the name they are imported with matches their name in the module source file. The default module, on the other hand, appears outside the braces, and can be assigned to any name. The unexported member launchSequence cannot be imported by another module.