[英]Is there a Javascript variable that represents local scope? Like global?
global
is an object containing any global variables (at least in Node.js, they're in window
in the browser). global
是一个包含任何全局变量的对象(至少在Node.js中,它们在浏览器的window
中)。
Is there a similar variable that represents the current scope? 是否有一个类似的变量代表当前范围? Local variables don't show up in
global
(for a good reason :) ) 局部变量不会显示在
global
变量中(有充分的理由:))
asdf = "hello";
var local = "hello";
console.log(global); // includes asdf
console.log(???); // includes local?
Yes. 是。 There is.
有。
No. You can't. 不,你不能。
Why? 为什么? JavaScript has only function scope - which is the execution Context .
JavaScript仅具有函数作用域-这是执行上下文 。 Within the execution Context , an Activation object (also known as
call object
) is used to create local variables as its property. 在执行上下文中 ,一个Activation对象 (也称为
call object
)用于创建局部变量作为其属性。 However, 然而,
...it is not a normal object as it has no prototype (at least not a defined prototype) and it cannot be directly referenced by javascript code.
...这不是普通对象,因为它没有原型(至少不是已定义的原型),并且无法由javascript代码直接引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.