开发者

Want to avoid eval AND Function constructor

开发者 https://www.devze.com 2022-12-15 10:21 出处:网络
Trying hard to replace the eval without using Function constructor.Stumped. I am not a newbie but not an expert either.

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);
        /开发者_JAVA百科/send resultData elsewhere...
   }

Help??


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消