开发者

Problem passing parameters with javascript eval function... What am i doing wrong?

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

开发者_Go百科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') 


Why do you need eval at all?

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜