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