给定的是以下模块结构:
// module A:
export let a = 1; // named export
export function inc() { a++; } // named export
// module B:
let b = 1;
export default b; // default export (equivalent to `export default 1`)
export function inc() { b++; } // named export
// module C:
let c = {};
export default c; // default export
// module E:
import a, {inc as incA} from "./A";
import b, {inc as incB} from "./B";
import c from "./C";
incA();
console.log(a); // logs 2, because "a" has a live connection to the export value
a++; // Error (because a is a live read-only view on the export)
incB();
console.log(b); // logs 1, because "b" is disconnected from the export value
b++; // Does this throw an error as well?
c.prop = true; // I think mutations are always allowed, right?
c = {}; // but are reassignment allowed too?
如果我有一个表达式(export default b
或export default 1
)的默认导出,则相应的导入与此导出值断开连接。考虑到这一点,这样的导入是否仍然是只读的,也就是说,我可以重新分配a
还是c
?