I got a string like:
settings.functionName + '(' + t.parentNode.id + ')';
that I want to translate into a function call like so:
clickedOnItem(IdofParent);
This of course will have to be done in JavaScript. When I do an alert on settings.functionName + '(' + t.parentNode.id + ')'; it seems to get everything correct. I just need to call the function that it would translate into.
Legend:
settings.functionName = clickedOnItem
t.parentNode.id = IdofParent
Seeing as I hate eval, and I am not alone:
Edit: In reply to @Mahan’s comment:
In this particular case,
settings.functionNamewould be"clickedOnItem". This would, at runtime translatevar fn = window[settings.functionName];intovar fn = window["clickedOnItem"], which would obtain a reference tofunction clickedOnItem (nodeId) {}. Once we have a reference to a function inside a variable, we can call this function by "calling the variable", i.e.fn(t.parentNode.id), which equalsclickedOnItem(t.parentNode.id), which was what the OP wanted.More full example: