9

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".

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.

screenshot of Chrome DevTools console

  • 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.

3
  • Is setting a breakpoint an option? Commented Sep 4, 2014 at 18:32
  • stackoverflow.com/questions/11969062/… Commented Sep 5, 2014 at 3:33
  • Both setting breakpoints and using heap snapshots requires me to interact with the DevTools GUI. I'm looking to programmatically search through the information displayed in DevTools. For the app I'm working on, there are far too many objects for me to want to manually sift through heap deltas or click-and-expand through stacks. Commented Sep 5, 2014 at 12:06

1 Answer 1

4

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

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.

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?

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?

Sign up to request clarification or add additional context in comments.

2 Comments

Is there a way to export Chrome's console.dir output tree (outside of screenshot + OCR) to a text file?
I don't know of any. Theoretically you should be able to fork the open-source debugger an add such a functionality…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.