I have string containg anonymus function definition, but how i can call this. Lets say function is like so:
var fn_str = "function(){ alert('called'); }";
Tried eval, but got an error that function must have a name.
eval(fn_str).apply(this); // SyntaxError: function statement requires a name
You can use Immediately Invoked Function Expression:
Immediately Invoked Function Expression
Another way is to use to a
Functionobject (If you have the function body string):