使用 javascript eval 函数传递参数时出现问题...我做错了什么?
像往常一样,我在测试了几个小时后来到这里,没有任何线索我做错了什么;-) 我不是 javascript 专家,所以我想这会导致一些翻白眼;-) 对此感到抱歉。我现在正尝试以更易读的方式编写代码。分离类中的函数等...我想要实现的是这样的:
modules.create('streamModule','leftColumn')
这将调用
streamModule.create()
现在我无法开始工作:
调用 modules.create('streamModule','leftColumn') 总是会导致
参考错误:leftColumn未定义???
调用中的id:eval(type +".create("+id+","+target")");总是正确传递,但目标参数不是???我做错了什么?
任何帮助将非常非常感激!谢谢你!
var modules = {
_map : [],
create: function(type,target) {
if(type == undefined) return false;
if(target == undefined) return false;
//Store id in map
this._map.push(id = createID());
//Call create function of module
eval(type +".create("+id+","+target")");
}
}
[...]
var streamModule = {
create: function() {
$.log(target)
}
}
[...]
modules.create('streamModule','leftColumn')
as usual i come here after testing around for hours and not having any clue what i am doing wrong ;-) I am not an javascript expert so i suppose this will cause some rolling eyes ;-) Sorry about that. I am now at a point where i tried to code somehting in a more readable way. Seperating functions in classes etc... What i want to achieve is something like this:
modules.create('streamModule','leftColumn')
which will call
streamModule.create()
NOW THE THING I DONT GET TO WORK:
Calling modules.create('streamModule','leftColumn') always results in
Reference Error: leftColumn is not defined???
The id in the call: eval(type +".create("+id+","+target")"); is always passed correctly but the target parameter is not??? What am i doing wrong?
Any help would be very very appreciated!!!!! Thank you!
var modules = {
_map : [],
create: function(type,target) {
if(type == undefined) return false;
if(target == undefined) return false;
//Store id in map
this._map.push(id = createID());
//Call create function of module
eval(type +".create("+id+","+target")");
}
}
[...]
var streamModule = {
create: function() {
$.log(target)
}
}
[...]
modules.create('streamModule','leftColumn')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么你需要
eval
?[...]
[...]
Why do you need
eval
at all?[...]
[...]