使用 Chrome DevTools 控制台以编程方式访问函数范围 [英] Programmatically accessing function scope using Chrome DevTools console

查看:30
本文介绍了使用 Chrome DevTools 控制台以编程方式访问函数范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我打开 Chrome (v35) DevTools 并检查对象时,控制台可以向我显示嵌套在函数中的内容,包括标记为函数范围"的内容.

When I open up Chrome (v35) DevTools and inspect an object, the console can show me things nested within functions, including something labeled as the '"function scope".

例如,在查看 stackoverflow.com 时,我可以看到一个全局 $ 对象包含另一个名为 Callbacks 的函数.Callbacks$ 一样,具有包含 ClosureGlobal 的功能范围.

For example, when looking at stackoverflow.com, I can see that there's a global $ object containing another function called Callbacks. Callbacks, as does $, has a functional scope containing Closure and Global.

  • 问题 1: 直接嵌套在函数中的命名对象与包含在其函数范围内的闭包中的某些对象有什么区别?
  • 问题 2: 如何在控制台中以编程方式引用函数作用域?window.$.Callbacks.????chrome.function???(window.$.Callbacks)
  • Question 1: What is the difference between some named object nested directly within a function and some object contained within a Closure in its function scope?
  • Question 2: How do I programmatically reference a function scope in the console? window.$.Callbacks.???? chrome.function???(window.$.Callbacks)

我问的原因是因为我正在寻找内存泄漏,并想根据对象类型和属性名称搜索函数闭包中保存的对象.

The reason I ask is because I'm looking for memory leaks and would like to search the objects held within functions' closures based on object types and property names.

推荐答案

直接嵌套在函数中的命名对象与包含在其函数范围内的闭包中的某些对象有什么区别?

What is the difference between some named object nested directly within a function and some object contained within a Closure in its function scope?

与函数直接嵌套的对象是函数对象的一个​​属性.例如,$.Callback 有一个值为 1.length 属性,它确实有一个 .prototype 属性,它确实从 Function.prototype 等中继承了 (__proto__)

The object nested directly with the function is a property of the function object. For example, $.Callback has a .length property with value 1, it does have a .prototype property, it does inherit (__proto__) from Function.prototype etc.

作用域中的对象是一个变量,可以从函数周围的作用域访问.请参阅JavaScript 闭包如何工作?

The object in the scope is a variable that is accessible from the scope that surrounds the function. See How do JavaScript closures work?

如何在控制台中以编程方式引用函数作用域?

How do I programmatically reference a function scope in the console?

你不能.范围不能以编程方式访问.我认为 devtools 也没有任何帮助程序来允许这样做.另请参阅如何在 Google Chrome 开发者工具中搜索范围变量?

You cannot. Scopes are not programatically accessible. I don't think the devtools have any helpers to allow this either. See also How do I search through scope variables in Google Chrome Developer Tools?

这篇关于使用 Chrome DevTools 控制台以编程方式访问函数范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆