有没有相当于“window”的es6模块范围? [英] Is there an es6 module-scope equivalent to `window`?
问题描述
'use strict'; var a = 1; function test(){window.b = }试验();执行console.log(a)的// aconsole.log(b); // b
是否有类似的(或不相似的! )方法为ES6中的当前模块范围分配vars
谢谢
模块环境包括所谓的声明式环境记录:
模块环境记录是一个声明式的环境记录,用于表示ECMAScript模块的外部范围。 p>
与全球环境相反,由 对象环境记录:
每个对象环境记录都是associa使用一个称为其绑定对象的对象。对象Environment Record将绑定与其绑定对象的属性名称直接对应的字符串标识符集合。
就像功能环境(也是声明式)一样,没有办法从另一个范围访问范围。
In Javascript, we can add global variables at any point using the window object:
'use strict';
var a = 1;
function test() {
window.b = 2;
}
test();
console.log(a); // a
console.log(b); // b
Is there a similar (or non-similar!) way to do assign vars to the current module scope in ES6?
Thanks
Module environments consist of so called declarative environment records:
A module Environment Record is a declarative Environment Record that is used to represent the outer scope of an ECMAScript Module.
In contrast to the global environment consist of an object environment record:
Each object Environment Record is associated with an object called its binding object. An object Environment Record binds the set of string identifier names that directly correspond to the property names of its binding object.
Just like with function environments (they are also declarative), there is no way to access the scope from another scope.
这篇关于有没有相当于“window”的es6模块范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!