Name: Anonymous 2012-05-25 16:51
The loop seems unnecessary but I don't know how to get rid of it.
I've seen some code where a tailor-made function
Thoughts? Help?!
var a = [
"Start ",
function(){return "middle "},
"end"
],
c = "";
for(var i = 0; i < a.length; i++){
var d = typeof a[i] === 'function' ? a[i]() : a[i];
c = c.concat(d);
}
console.log(c);var a is generated once at runtime from an array of strings and another array of functions. The functions obviously return dynamic content so doing something like this var a = a[0]+a[1]()+a[2]; by loop once at runtime is not an option since I'd be saving the result of the function and not the function itself.I've seen some code where a tailor-made function
function(){return a[0]+a[1]()+a[2];} is created at runtime that returns the strings and functions() correctly but I don't know how to achieve something like that. In the example I saw the JavaScript source stored in a "string" and editted via String methods and then eval() evaluated. I don't even know if it's worth it in that case.Thoughts? Help?!