Liang
Liang

Reputation: 1187

How can I import selected functions from a module as an object in ES2015?

I want something like this

import { stuffA, stuffB } as myStuff from 'stuff'

I know this won't work, you know what I mean with this code, do you? Actually there's something similiar in ES2015 like

import * as myStuff from 'stuff'

but I only want part of the content from stuff

and I know this would work

import { stuffA, stuffB } from 'stuff'
const myStuff = { stuffA, stuffB }

but this approach is ugly isn't it?

And I want the result to be like

myStuff = {
  stuffA: stuffA,
  stuffB: stuffB
}

Upvotes: 1

Views: 35

Answers (1)

Michał Perłakowski
Michał Perłakowski

Reputation: 92521

I don't think it's possible. What's so wrong with

import { stuffA, stuffB } from 'stuff'
const myStuff = { stuffA, stuffB }

anyway?

Upvotes: 2

Related Questions