官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 辉县市| 肥西县| 噶尔县| 合江县| 新兴县| 化州市| 岳阳市| 郴州市| 吉安县| 道真| 太原市| 密云县| 德江县| 星子县| 仙游县| 榆林市| 竹溪县| 朝阳区| 淮北市| 武定县| 翼城县| 古蔺县| 华阴市| 蒙自县| 天柱县| 南汇区| 孝昌县| 慈利县| 白玉县| 本溪| 庆元县| 福建省| 永靖县| 建瓯市| 嘉兴市| 黄石市| 崇信县| 黑河市| 名山县| 隆化县| 金乡县|