javascript - Avoiding eval() in a particular scenario -
javascript - Avoiding eval() in a particular scenario -
i have read @ several places should avoid using eval in our javascript code. but, have scenario, not able remove this. need help that
var levels=[]; for(var k=0;k<levels.length;k++){ var levelsarray={}; levelsarray["name"]=levels[k].name; levelsarray["caption"]=levels[k].caption; var prop = levels[k].name; eval("levelsarray[\"memberprovider\"]= function (item) { homecoming item." + prop + ";}"); levels.push(levelsarray); }
i hope, code clear in trying do.
levelsarray.memberprovider = (function(p) { homecoming function (item) { homecoming item[p]; }; })(prop);
javascript eval
Comments
Post a Comment