Is there a way to create a function at runtime with content that is unknown (but trusted) at design-time WITHOUT using eval()?
Basically I am trying to create a "hard coded" function for performance reasons as it is going to be called many, many times. Only the "hard coding" will be done once at runtime just before the many calls begin.
(untested example)
var strFuncString = 'function(){';
for (some loop)
{
strFuncString+='DoSomething()'; //if this can be made to reference an object obtained for the for-loop then even better - i.e. Myfunc+=Obj.DoSomething
}
var MyFunc = eval(strFuncString '}');
SomeProcessThatCallsItsArgALot(MyFunc);
I tried this in the debugger but unsurprisingly it didn't work
((function(){console.log(1);} )+( function(){console.log(2);}))()