I'd like to pass a function as parameter in JavaScript, that function is a reference onto a function stored globally
alertHello = function() {
alert("Hello")
}
for instance, I'd like to create a table from JSON array, which has an actions embedded array.
So I'd like to pass each function stored in actions attribute in my JSON object like this :
{
...
actions : [
{func : alertHello, icon : myIcon}
]
}
So when I create the table, I add a column based on the actions attributes :
for(var i = 0; i < actions.length ; i++)
{
body += "<button class='ui primary icon button' onclick="+actions[i].func+"><i class='"+actions[i].icon+" icon'></i></button>";
}
But I got a "function statement requires a name" error