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

后端 未结 8 1184
盖世英雄少女心
盖世英雄少女心 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:42

    You can't access these variables because they are defined within a functional closure. The only way you could do it is if you made a global reference to them outside your function's scope.

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

提交回复
热议问题