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

134
Vistas
Names spacing JavaScript imports from native modules

I am migrating code that used to not use native JS modules.

// File: form.js
// `lc` is a global object I attach each file's functions to.
let lc = window.lc || {}
lc.form = {};
lc.form.add = function() {
   // add a form
}

And then would be called as lc.form.add(), which is nice because the word add has context.

However now that I am changing the code to use JS modules:

// File: form.mjs
export function add() {
   // add a form
}

And then would be called as add(), which has no context. Now I understand I could do:

import {add as formAdd} from '/form.mjs'

But thats like a step backwards to start smurf naming all imported things.

Is there a way to import the module like in Python, and then call functions of the modules. E.g. use dot etc notation to access it's function, something like this:

import '/form.mjs' as form
form.add()
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're looking for a namespace import:

import * as form from '/form.mjs';
form.add();
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