javascript eval method

后端 未结 4 1504
孤街浪徒
孤街浪徒 2021-01-14 21:47

How can I watch variable values inside of javascript eval() method? And is it possible to \"step into\" and \"step over\" in eval method? For example, with a code like this:

相关标签:
4条回答
  • 2021-01-14 22:23

    It is possible. you have to use SourceMap with your source code. Take a look at the source map which has en extensive information about this technique.

    0 讨论(0)
  • 2021-01-14 22:30

    if variable is not exist how could you know it's value? - noway. And... eval === evil.

    0 讨论(0)
  • 2021-01-14 22:34

    you can't inside the eval method. the code you give it is no code but a string. after the eval() then it becomes code and you can inspect it. This also depends on what tools you use to debug your script. In Chrome if you click Pause on exception, and execute your eval. it will break (because b is undefined) and jump in the evaluated code where you can step over, in and out. you can also use new Function("code goes here")() to evaluate code

    0 讨论(0)
  • 2021-01-14 22:38

    Although not thoroughly documented or advised, you can watch local variables.

    var reference;
    
    function alerta(){
      alert(reference[0]);
    }
    
    // Desired to be watched must be called as function arguments
    (function(a){
      reference = arguments;
    
      a = 'taco';
      alerta();
      a = 'updatedValue';
      alerta();
    
    })()
    

    http://jsbin.com/oragan

    0 讨论(0)
提交回复
热议问题