0

I need to use these javascript functions inside this file. Said functions are not in a namespace. I dont want to edit that file. How can i import the functions into a namespace in a different file? Preferably without using any third party library.

O. Altun
  • 685
  • 7
  • 20

1 Answers1

0

Say you have header.js (may be a library) which has

export {
    funcA,
    funcB,
    funcC,
    ...
}

In another file (may be your file) user.js (assume it is in the same folder), you can write

import * from "./header.js"

Then in user.js, you can use funcA, funcB, funcC and any other functions that header.js exports.

And to avoid name conflict, you can write

import * as header from "./header.js"

Then in user.js, you can use header.funcA ...

Is this you need?

Wenbo
  • 1,212
  • 8
  • 17