How override eval function in javascript?

前端 未结 6 1687
滥情空心
滥情空心 2021-01-17 19:00

For example:

(function() {
      var proxied = window.eval;
      window.eval = function() {
        return proxied.apply(this, arguments);
      };
    })()         


        
6条回答
  •  爱一瞬间的悲伤
    2021-01-17 19:43

    Maybe I didn't understand the question correctly, but I "override" eval()by creating a myEval() function that has the original eval() inside it and execute addition steps in myEval().

    function myEval = function(value){
        //do your stuff here
        //for example
        try {
            value = eval(value)
        } catch (error) {
            console.log(error)
            value = NaN
        }
        return value
    }
    

提交回复
热议问题