How to turn a String into a JavaScript function ca

2018-12-31 17:16发布

This question already has an answer here:

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

13条回答
不再属于我。
2楼-- · 2018-12-31 18:14
window[settings.functionName](t.parentNode.id);

No need for an eval()

查看更多
登录 后发表回答