【发布时间】:2023-03-09 13:15:02
【问题描述】:
在 Javascript 中,我们可以在任何时候使用 window 对象添加全局变量:
'use strict';
var a = 1;
function test() {
window.b = 2;
}
test();
console.log(a); // a
console.log(b); // b
在 ES6 中是否有类似(或不类似!)的方式将变量分配给当前模块范围?
谢谢
【问题讨论】:
-
幸好没有。
-
检查2ality.com/2015/02/es6-scoping.html滚动到
The global object
标签: javascript scope ecmascript-6