在JavaScript调试器中,我可以手动检查函数的作用域链。例如,在执行此代码片段中的
foo()
时:
var x1 = "global";
var foo = (function main () {
var x2 = "inside obj";
return function internalFoo () {
var x3 = "inside internalFoo";
console.log (x1+','+x2+','+x3); // get the scopes
};
})();
foo ();
在 console.log
上设置断点后,我看到以下作用域:
有没有一些方法可以以编程方式实现这个功能?
如何检查每个作用域级别定义的内容?