如何从 <function scope> 的闭包访问 Chrome 开发者工具的监视面板中的值?
How to access values from <function scope>'s Closure in Chrome Developer tool's Watch panel?
我有一个复杂的javascript对象,它是由某些第三方工具生成的,看起来像这样(内部Chrome 开发人员工具监视面板):
我有兴趣阅读 i
对象的 text
和 value
属性。
我以前从未见过这样的 <function scope>
东西。在这种情况下,
How to access values from <function scope>
's Closure in Chrome Developer tool's Watch panel?
还是不可能?
A closure is a special kind of object that combines two things: a function, and the environment in which that function was created. The environment consists of any local variables that were in-scope at the time that the closure was created.
来源: MDN Closures
您看到的 i
对象是在过去的某个时间点创建的,您暂停的函数是在创建该对象的同一个外部函数中创建的。当内部函数访问外部函数的变量时,会为"remember"它们创建一个闭包。
您不能直接访问封闭变量。
您可以像这样更改日期值:
- 右键单击“作用域”中的变量(在源选项卡的右侧)。
- select“将对象存储为全局变量”。
- 现在您将跳转到控制台并拥有一个新的全局变量“temp1”。 (重复这样做会增加1)
- 键入 temp1.setTime([your-date-value]) 将更改它的值。
(在 Chrome 版本 88 中确认)
我有一个复杂的javascript对象,它是由某些第三方工具生成的,看起来像这样(内部Chrome 开发人员工具监视面板):
我有兴趣阅读 i
对象的 text
和 value
属性。
我以前从未见过这样的 <function scope>
东西。在这种情况下,
How to access values from
<function scope>
's Closure in Chrome Developer tool's Watch panel?
还是不可能?
A closure is a special kind of object that combines two things: a function, and the environment in which that function was created. The environment consists of any local variables that were in-scope at the time that the closure was created.
来源: MDN Closures
您看到的 i
对象是在过去的某个时间点创建的,您暂停的函数是在创建该对象的同一个外部函数中创建的。当内部函数访问外部函数的变量时,会为"remember"它们创建一个闭包。
您不能直接访问封闭变量。
您可以像这样更改日期值:
- 右键单击“作用域”中的变量(在源选项卡的右侧)。
- select“将对象存储为全局变量”。
- 现在您将跳转到控制台并拥有一个新的全局变量“temp1”。 (重复这样做会增加1)
- 键入 temp1.setTime([your-date-value]) 将更改它的值。
(在 Chrome 版本 88 中确认)