Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
es6 modules: import specific-functions as aName

I'd like to import specific functions from another module. But I faced naming collision: I have similar function names in my importing file. I'd like to do something like this:

// exporterFile.js

export {
    set,
    get,
    has,
    foo,
    bar,
}

// implementation code for set, get, etc.
// importerFile.js

import {get, set} as exporter from "exporterFile.js"

function get() {
    // some code and call set from exporter
    exporter.set(something)
}

I know I could import * as exporter from "exporterFile.js" but it lacks readability and does not show what methods (functions) I am using from the exporter file.

Also, I know I could import {get as exporterGet, set as exporterSet} from "exporterFile.js" but it is not so readable.

Is there an elegant, clear, readable way to import selected functions from a module without naming collision? If not, what is the best practice and approach and suggestion: readability is very important, tree-shaking is a consideration as well.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There are no alternatives to the two ways you already mentioned. Readability is subjective, but both exporterGet() and exporter.get() are good choices that are common. If you explicitly want to list all the used function in the import statement itself, you will have to give them individual aliases. Tree shaking tools will be able to handle both formats.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda