1

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

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

3 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.