views:

20

answers:

1

Hi everybody,
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') 
+2  A: 

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);
KennyTM
+1, was just typing something similar myself. The first rule of using *eval()* is that you should avoid using it.
Andy E
Because i get: type.create() is not a function... ?already tried that :-(
Bosh
SORRRY.. I am such an retard.... called it with a string... using modules.create(streamModule, 'leftColumn'); works... SORRY
Bosh