上QQ阅读APP看书,第一时间看更新
The default import/export
So far, we have been very explicit with what we import and what we export. We can, however, create a so-called default export, which looks somewhat different to consume:
export default class Player {
attack() {}
move() {}
}
export const PI = 3.13;
To consume this, we can write the following:
import Player from './module';
import { PI } from './module'
Note especially the first row where we no longer use the curly brackets, {}, to import a specific construct. We just use a name that we make up. In the second row, we have to name it correctly as PI, but in the first row we can choose the name. The player points to what we exported as default, that is, the Player class. As you can see, we can still use the normal curly brackets, {}, to import specific constructs if we want to.