Es6 import from underscore

I wanted to double check to make sure that I understand import enough to know if import {_.identity} from 'underscore' normal against import _ from 'underscore' ? This is the only use of underscore if a specific file.

thanks for the help

+5
source share
1 answer

Looks like you are very close!

There are several ways to do this.

IMO the cleanest way to do this is as follows:

 import { map, reduce, somethingElse } from 'underscore' 

Lets you call these methods like this:

 map(things, thing => { ... }) 

The parameter '{map, reduce} = ...' is the destructive purpose of es6s. See the Mozilla docs page for more details.

Another way:

 import map from 'underscore/map' import reduce from 'underscore/reduce' 

Personally, I'm not a big fan of this, as it may start to be a little more cumbersome, as more methods get involved, but it has one slight advantage, you can name the link as you like:

 import mappy from 'underscore/map' import reducerify from 'underscore/reduce' 

Although I would not recommend using these names!

+7
source

Source: https://habr.com/ru/post/1257914/


All Articles