Search code examples
javascriptjqueryspry

Can javascript eval() take variables name and replace them before using


Many thanks for reading ,

Problem context: Use search function of spry in more than one accordion panel.

I am trying to use eval (since it is the only way I can think of) to accomplish this simple thing:

var ds1 = new Spry.Data.XMLDataSet("ajaxxmllogdaneiz1.php",'root/row]');

var ds2 = new Spry.Data.XMLDataSet("ajaxxmllogdaneiz2.php",'root/row]');

var str1="ds";

var str2= 1;

var result= str1.concat(str2);

//result is now ds1

eval ("result.filter(filterFunc)");

I would like ds1.filter(filterFunc) to be called but result.filter(filterFunc) is called. Is there a way for ds1.filter(filterFunc) to be called with eval or alternatives (Jquery?)? Many thanks Dinos


Solution

  • For using the value of result instead of "result" itself, you can do:

    eval (result+".filter(filterFunc)");