var arr = ['abc','xyz'];
$.each(arr, function(i,val){
var val = val; //where I got abc, xyz here
if(some condition){
//run abc function but I don't want to do abc(), possible?
}
});
function abc(){}
function xyz(){}
而不是硬编码我的函数名称像abc(),有没有我可以将字符串(val)转换为可执行函数的任何位置?通过这种方式,我可以通过在数组中添加值来执行任何函数。将字符串转换为可执行函数javascript
可能重复的[有没有一种方法来创建一个从字符串与JavaScript的功能?](http://stackoverflow.com/questions/7650071/is-there-a-way-to-create-a-function -from-a-string-with-javascript) – alexi2