I am trying to call a function using a variable with it's name.
Here's the code:
var selectedFunc = 'func2';
var myModule = {
func1: function() {
//something here
},
func1: function() {
//something here
}
};
myModule.selectedFunc();
I would normally do this:
myModule.func1();
which will work but I'm trying to use the variable to define it's name, which is not working.
How can I fix this issue?