I recently knew this function and I was surprised by its power, it was very useful to me, but after using it I heard comments that it was not safe.
I would like to know if this usage can cause security problems and if there is an alternative to eval () when you want to generate javascript code dynamically, but in a more secure way.
Example usage by my application:
var valPeriodos = "";
var next = ".next()";
for (i = 1; i <= numPeriodos; i++) {
eval('var tdVal' + i + '=$(this).parent().parent().find(".vp1").parent()' + valPeriodos + ';');
valPeriodos += next;
eval('val_' + i + ' = tdVal' + i + '.find(".valInputOn").val()');
}
In this code I get values from a PivotTable that have columns according to the number of periods and save them in variables.