global
在浏览器中,顶层作用域传统上是全局作用域。这意味着 var something
将定义一个新的全局变量,ECMAScript 模块除外。在 Node.js 中,这是不同的。顶层作用域不是全局作用域;Node.js 模块内的 var something
对于该模块而言是本地的,无论它是 CommonJS 模块 还是 ECMAScript 模块。
¥In browsers, the top-level scope has traditionally been the global scope. This
means that var something
will define a new global variable, except within
ECMAScript modules. In Node.js, this is different. The top-level scope is not
the global scope; var something
inside a Node.js module will be local to that
module, regardless of whether it is a CommonJS module or an
ECMAScript module.