简体   繁体   English

如何访问值<function scope>在 Chrome 开发者工具的观察面板中关闭?

[英]How to access values from <function scope>'s Closure in Chrome Developer tool's Watch panel?

I have a complex javascript object which is generated by some third party tool , which looks like this (inside Chrome Developer Tools Watch panel):我有一个复杂的 javascript 对象,它是由一些第三方工具生成的,它看起来像这样(在 Chrome Developer Tools Watch 面板中):

在 Chrome 开发者工具的 Watch 窗格中访问 <function scope> 的 Closure 中的值

I'm interested in reading those text and value attributes of i Object.我有兴趣阅读i Object 的那些textvalue属性。 I've never seen such <function scope> thing before.我以前从未见过这样的<function scope>东西。 In such cases,在这种情况下,

How to access values from <function scope> 's Closure in Chrome Developer tool's Watch panel?如何在 Chrome Developer tool 的Watch面板中从<function scope>Closure访问值?

Or is it not possible?或者不可能?

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.环境由创建闭包时在范围内的任何局部变量组成。

Source: MDN Closures来源: MDN 关闭

The i object you are seeing was created at some point in the past, and the function you have paused in was created within the same outer function that created the object.您看到的i对象是在过去的某个时间点创建的,而您暂停的函数是在创建该对象的同一个外部函数中创建的。 When the inner function accesses the variables of the outer function, a closure is created to "remember" them.当内部函数访问外部函数的变量时,会创建一个闭包来“记住”它们。

You can't access the closed over variables directly.您不能直接访问已关闭的变量。

You can change a Date value like this:您可以像这样更改日期值:

  • right click on your variable in "Scope" (on the right of your source tab).右键单击“范围”中的变量(在源选项卡的右侧)。
  • select "store object as global variable".选择“将对象存储为全局变量”。
  • now you will have jumped to console and have a new global variable "temp1".现在您将跳转到控制台并拥有一个新的全局变量“temp1”。 (1 will increased if you repeatly doing this) (如果你重复这样做,1会增加)
  • type temp1.setTime([your-date-value]) will change the value of it.输入 temp1.setTime([your-date-value]) 将改变它的值。

(confirmed in Chrome verion 88) (在 Chrome 88 版中确认)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM