Dynamically change function name in javascript
5 answers
EVAL should always be the last option
To use dynamic name in function names, you can use Windows object.
Here's an example:
var id = '2';
function map2() {
alert('me called');
}
window["map"+id]();
Demo
Your use would be something like this
$('a').on('click',function(e){
e.preventDefault();
var id = $(this).attr('id');
infowindow2.open(map, window['map'+id]());
});
0
source to share