You can use Expression Exposed Expression Expression:
var fn_str = "function(){ alert('called'); }";
eval('(' + fn_str +')();');
Instant call function expression
Another way is to use an object Function(if you have a function body string):
var func = new Function("alert('called')");
func.apply(this);
source
share