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')
答案 0 :(得分:2)
为什么你需要eval
?
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
type.create(id, target);
}
[...]
var streamModule = {
create: function(id, target) {
$.log(target)
}
}
[...]
modules.create(streamModule, leftColumn);