I am trying to make a news system. I have a table where each element is a function producing text.
I have a loop that checks whether news+number is a function or undefined. If it is a function, then I push news+number to the array [number].
I am using eval, because i don't know any other way to push the function name and the number to the array.
CODE:
var tablicaNewsow = [news1,news2]
function addNews ()
{
var counterArray = 0;
var fName = " ";
fName = "news1";
while (eval('typeof' + " " + fName) == "function")
{
//---------------sprawdzenie czy news istnieje----------
fName = "news" + (counterArray+1);
if (eval('typeof' + " " + fName) == "function")
{
//------------jest news
tablicaNewsow.push(eval(fName+"()"));
}
else
{
//-----------nie ma newsa
}
counterArray++;
}
}
NOTE:This is a code segment from my system, which pushes functions in the array.
Sorry for my bad English.
eval
thing, you should probably think again why do you even need it! – gdoron Oct 16 '12 at 16:08