开发者

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);
        /开发者_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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜