[英]How can i import a javascript library that does not use namespace in into a namespace without editing the file library is in?
I need to use these javascript functions inside this file.我需要在这个文件中使用这些 javascript 函数。 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.最好不使用任何第三方库。
Say you have header.js
(may be a library) which has假设你有header.js
(可能是一个库),它有
export {
funcA,
funcB,
funcC,
...
}
In another file (may be your file) user.js
(assume it is in the same folder), you can write在另一个文件(可能是你的文件) user.js
(假设它在同一个文件夹中),你可以写
import * from "./header.js"
Then in user.js
, you can use funcA
, funcB
, funcC
and any other functions that header.js
exports.然后,在user.js
,你可以使用funcA
, funcB
, funcC
以及任何其他职能header.js
出口。
And to avoid name conflict, you can write并且为了避免名称冲突,你可以这样写
import * as header from "./header.js"
Then in user.js
, you can use header.funcA
...然后在user.js
,您可以使用header.funcA
...
Is this you need?这是你需要的吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.