Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
How can I import all the function from other file to current file?

I have one file containing many functions. Similar to below,

export const func1 = () => {
}

export const func2 = () => {
}

export const func3 = () => {
}

export const func4 = () => {
}

Now I want to use all this function in another file.

Method 1 is import {func1, func2, func3, func4} from 'path'.
Method 2 (which I don't want to use) is import * as access from 'path'

Method 1 approach is what I am using right now. But when func file gets bigger, this will not be readable. So, how to use the functions without creating aliases and simply func1() and not access.func1() ?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You should really make up your mind between the two as they are the most readable and clean solutions.

First option can be made more readable with:

import {
  func1,
  func2,
  func3,
  func4
} from 'path';

Nevertheless, if you really want an alternative syntax without having to list the exports, it is technically possible to load all the exported properties into the global object through:

Object.assign(globalThis, require('path'))

However, I would highly advise against this as it'll make your code very difficult to maintain. Global variables are painful enough, but unknown global variables coming from another file will be a nightmare. Use at your own risk.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can import with your Method 2 and then can use object destructuring on the access object like this and use them directly.

import * as access from 'path';

const {func1, func2, func3, func4} = access;

func1();
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda