export_once 就像在 Typescript 中一样

export_once like in Typescript

当我有类似的东西时

File1.ts

function someFunction(){...}

export default someFunction();

然后

File2.ts

import File1 from "./File1";

File3.ts

import File1 from "./File1";

File1.ts中的export default someFunction();会执行一次并缓存结果还是每次导入都会触发函数执行?

The export default someFunction(); in File1.ts will be executed once

是的,在这种情况下,两个模块将收到相同的 File1.ts 副本。这种行为不是特定于 TypeScript 的,也可以在 Node.js 中的浏览器或本机 ECMAScript 模块中看到。