js 文件中的代码是否在导入过程中运行?如果是,那么是一次还是每次? 例如
// a.js
console.log("A");
const a = "a";
export default a;
// b.js
import a from "./a"; // => console logs?
// c.js
import a from "./a"; // => console logs again?
最佳答案
是的,确实如此,恰好一次。
参见 http://www.ecma-international.org/ecma-262/6.0/#sec-abstract-module-records :
Do nothing if this module has already been evaluated. Otherwise, transitively evaluate all module dependences of this module and then evaluate this module
关于javascript - ES6 模块导入是否执行导入文件中的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37325667/