【发布时间】:2013-03-23 03:26:56
【问题描述】:
我想访问在私有上下文中创建的变量。我正在创建一个这样的私有上下文:
(new Function("var a = 'hello'; console.log('this', this);")).call({});
// outputs -> this Object {}
我在 call'ing 使用空上下文的函数。但是this 不包含a 变量。无论如何,console.log 怎么可能在空上下文中工作?
【问题讨论】:
-
为什么不直接调用 console.log('this', a); ?
-
因为我想访问在上下文中创建的所有变量。
标签: javascript variables object scope private