[英]Javascript how to use modules to Import/Export all from file?
With this code I am able to successfully import / access variables and functions when they are individually exported, but I want to be able to export the entire file in a single declaration.使用此代码,我能够在单独导出变量和函数时成功导入/访问它们,但我希望能够在单个声明中导出整个文件。 I've tried a number of variations from here but cannot achieve this.
我从这里尝试了许多变体,但无法实现这一点。
script.js脚本.js
import * as testImport from './test.js';
console.log( testImport.testVar ); // Returns 'Test Variable'
console.log( testImport.testFunc() ); // Returns 'Test Function'
test.js测试.js
export let testVar = 'Test Variable';
export function testFunc() {
return 'Test Function';
}
desired ( without individual 'exports' )需要(没有单独的“出口”)
let testVar = 'Test Variable';
function testFunc() {
return 'Test Function';
}
export * // ?
There is no such thing like you ask for, because it conflicts diametrically with the intention behind modules.没有像您要求的那样的事情,因为它与模块背后的意图完全冲突。
The whole point of modules is too keep all variables private to the module with the exception of making those explicitly exported available for importing .模块的重点是保持所有变量对模块私有,除了使那些显式导出的变量可用于导入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.