javascript - Is there an es6 module-scope equivalent to `window`? - Stack Overflow

In Javascript, we can add global variables at any point using the window object:'use strict';

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

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

Share Improve this question asked Oct 6, 2015 at 3:32 JarradJarrad 1,02712 silver badges19 bronze badges 2
  • 1 Fortunately there is no. – zerkms Commented Oct 6, 2015 at 3:34
  • Check 2ality./2015/02/es6-scoping.html scroll to The global object – Tushar Commented Oct 6, 2015 at 3:36
Add a ment  | 

1 Answer 1

Reset to default 8

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744770705a4592741.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信