Want to avoid the eval AND Function constructor

Cannot replace eval without using the Function constructor. Dead end. I am not a beginner, but not a specialist.

jslint says this is evil; when I replaced it with the Function constructor, he said it was just an eval () form!

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

Help??

+3
source share
1 answer

Can't you just pass the function object to your script? eg

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 requires requestObject to be a function object, not a string.

+3
source

Source: https://habr.com/ru/post/1727057/


All Articles