M G
M G

Reputation: 41

How to import multiple functions from module into one object in JavaScript?

I want something like this:

import {get, set} as moduleName from 'module-name'

moduleName.get()

The reason is because sometimes methods of different modules can have the same name, and I don't want to import the whole module because of it

Upvotes: 3

Views: 2675

Answers (2)

mahooresorkh
mahooresorkh

Reputation: 1444

There is no such thing as:

import {get, set} as moduleName from 'module-name'

You can either do it like this:

import * as moduleName from 'module-name';
moduleName.get();  //all the exported items will be accessible.

Or this:

import {get as moduleNameGet, set as moduleNameSet} from 'module-name';
moduleNameGet();

Please check this out

Upvotes: 2

Mr.Developer
Mr.Developer

Reputation: 545

You can use below syntax

import * as module from "module-name";

Upvotes: 0

Related Questions