Wildcard or asterisk (*) vs named or selective import es6 javascript

前端 未结 4 934
一个人的身影
一个人的身影 2020-12-08 09:39

Just wondering which one is the best way to use import:

import * as Foo from \'./foo\';

VS:

import { bar, bar2, bar3 } from \'./fo

4条回答
  •  难免孤独
    2020-12-08 09:59

    I agree with @Tamas.
    If you require the full access to all exports in the target file, then you can use the import * as Foo from './foo'; or import foo from './foo':

    but if you need to use specific function or const then better avoid "import *" and be explicit what you needs to do.

提交回复
热议问题