I am trying to create a variable which when put together with another variable creates a function call. EG:
var firstexpression = "MyFunction";
var secondexpression = "();";
var totalexpression = firstexpression + secondexpression;
And this would make totalexpression read as "MyFunction();" I want to be able to basically call this function from within an Array. This is what I came up with:
<!DOCTYPE html>
<html>
<body>
<p>test</p>
<p id="demo"></p>
<script>
function Banana() {
return "Junk";
}
var junker = "Banana" + "();";
var fruits = [junker];
document.getElementById("demo").innerHTML = fruits[0].toString();
</script>
</body>
</html>
This just returns "Banana();", but it doesn't run "Banana();". I know it isn't as simple as what I put up there, but there has to be a way to do something like this in Javascript. Does anyone have any suggestions to this? I know this can probably be done with JQuery. But I want to avoid JQuery if at all possible. Thank you!