You can make a strfunction body and use New Functioninstead eval.
var fn = new Function([param1, param2,...], str);
And reuse it by calling fn(p1, p2,...)
Or use eval and do strsomething like
var fn = eval("(function(a){alert(a);})")
source
share