假设我们有四个module,A, B,C和D
在module中A:
console.log("A evaluated")
function AClass {
console.log("A constructor")
}
var aObj = new AClass()
export default aObj;
在module中B:
import aObj from A
export default "B"
在module中C:
import aObj from A
export default "C"
在module中D:
import b from B
import c from C
import aObj from A
那么当moduleD被评估时,A evaluated和A constructor将在控制台中打印多少次?
这种行为是否在ES6 标准中描述?如果我希望一个module无论直接或间接导入多少次都只评估一次,该怎么办?有没有人对此有任何想法?