Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
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 answers
Answer question

0

You're looking for a namespace import:

import * as form from '/form.mjs';
form.add();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!