是否可以在代码中访问["[[FunctionLocation]]"]google chrome开发人员工具在使用控制台日志功能时显示的属性?
2014 年, JS 代码无法从闭包外部访问闭包内部的变量。从那时起,Chrome 的内部结构已更改为使用[[Scopes]]而不是Closure.
Chrome DevTools 现在(2018 年)可以以[[Scopes]]编程方式读取吗?如果是这样,是否有现有的 DevTools 扩展可以做到这一点?
用例:检查使用 RequireJS 加载的 UMD 模块内的变量。我知道我可以使用面板在断点或语句处执行此操作,但希望即使不在断点处也能执行此操作。debuggerScopes
编辑截至 2017 年,无法访问[[FunctionLocation]],但我不知道[[Scopes]]。
我调查了以下内容但没有成功(模块工厂函数名称main):
console.dir(),但没有以编程方式访问 的输出console.dir()。我可以console.dir({main})手动使用然后扩展结果,但不能以编程方式。从 DevTools 控制台,我可以使用inspect({function})per this。这让我更接近,但不是[[Scopes]]:
> var x = inspect({main})\n> x.main.name\n\xe2\x86\x90 "main"\n> x.main[Symbol(\'Scopes\')]\n\xe2\x86\x90 undefined\n> x.main[\'[[Scopes]]\']\n\xe2\x86\x90 …Run Code Online (Sandbox Code Playgroud)javascript closures google-chrome inspect google-chrome-devtools