Console access to Javascript variables local to the $(document).ready function

后端 未结 8 1182
盖世英雄少女心
盖世英雄少女心 2021-01-03 23:27

How can I access some variables inside

$(document).ready(function(){
    var foo=0;
    var bar = 3;
});

from Google chrome console? If I

相关标签:
8条回答
  • 2021-01-03 23:54

    define them outside of $(document).ready() and then access them inside as well.

    var foo = 0, bar = 3;
    $(document).ready(function(){
        alert(foo);
    });
    
    0 讨论(0)
  • 2021-01-03 23:58

    Actually there is a hackish way around it. You should probably not use it. Set a Breakpoint. That being said, here's the code:

    $(document).ready(
        readyClosure = function(access){
            var x = 5; 
            return eval(access);
        }
    );
    readyClosure('x'); // returns 5
    
    0 讨论(0)
提交回复
热议问题