Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to avoid eval AND Function constructor

Trying hard to replace the eval without using Function constructor. Stumped. I am not a newbie but not an expert either.

jslint says this is evil; when I replaced it with a Function constructor, it said that was just a form of eval()!

   evaluateEventScript: function(requestObject) {
        var resultData;
        resultData = eval(requestObject.script);
        //send resultData elsewhere...
   }

Help??

like image 241
Dave Avatar asked Oct 26 '25 06:10

Dave


1 Answers

Can't you simply pass a function object in your scenario? e.g

var c = function(){
   ...
}


var evaluateEventScript = function(requestObject) {
    var resultData;
    resultData = requestObject();
    //send resultData elsewhere...
}

evaluateEventScript(c);

Or something in this form? this can work without eval or Function constructor. but it requires the requestObject to be a function object, and not a String.

like image 179
Eran Medan Avatar answered Oct 28 '25 20:10

Eran Medan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!