Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
409 views
Welcome To Ask or Share your Answers For Others

1 Answer

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...