ESM 符号绑定
下面的代码输出?
js
import { count, increase } from './counter.js';
import * as counter from './counter.js';
const { count: c } = counter;
increase();
console.log(count);
console.log(counter.counter);
console.log(c);js
var count = 1;
export { count }
export function increase(){
count++;
}答案
2
2
1解释如下:
- 使用
import { count }导入的count跟模块counter导出的count是同一个东西(符号绑定) - 使用
import * as counter导入的counter.count也是同一个东西(符号绑定) - 使用
const { count: c } = counter对象解构的方式产生的c拥有独立的内存空间
