2

当我使用 web worker 阅读一个开源项目时,我发现一旦 worker 导入了一个模块,那么调用导入的模块会导致整个模块的重新加载。

例如主线程:

一个.js

const  T = new Date().getTime(); //init the variable once the moudle is loaded
export default T;

工人.js:

import T from a;

const a  = T; // this will result in different value for the varible `T`

这是理想的实现吗?如何避免这种情况,或者我是否可以在 worker 中获取全局启动的变量?

4

0 回答 0