【发布时间】:2012-04-03 02:35:55
【问题描述】:
我正在尝试删除此函数中的 eval 语句。我已经习惯了 this[whatever] 样式替换,但在这种情况下它不起作用。 看看:
var App = (function(fw) {
var somevar1 = "hello";
var somevar2 = "world";
this.get = function(what) {
return eval(what);
}
});
var app = new App({some: "thing"});
// now for the use:
console.log(app.get("somevar1"),app);
在函数中,我所有正常的“评估清理”选项都不起作用,例如,我不能使用:
return this[what]
return [what]
return app[what]
return new Function(what);
这肯定不是需要 eval 的奇怪情况吗? .. ps 我必须注意,我不能重新调整 App 内的变量范围,因为它是庞大代码库的一部分。
这里有一些东西可以摆弄:
【问题讨论】:
标签: javascript jquery eval scope