6

When I create a blank object:

var o = {};

Why can't I view the '__proto __' object when I create a new object, but I can when I add a function?

enter image description here


Edit: For completeness, to create a truly blank object (no prototypal linkage), we could do:

var o = Object.create(null);

But for the purposes of the question, I'll use the o = {} syntax.


Edit 2: This shows the prototype linkage upon a object creation, so the __proto's __ are there but I can't view them in the debugger unless I add a function object.

enter image description here


Edit 3: It works in Firefox:

enter image description here

Hristo
  • 45,559
  • 65
  • 163
  • 230
Data
  • 1,337
  • 11
  • 17
  • 3
    Why did the makers of this particular debugger (which you haven't named) implement their console like this? Who knows? Perhaps they figured it only made sense to make an object expandable when it has properties. – JLRishe Mar 10 '15 at 19:55
  • I'm using Google chrome Version 40.0.2214.115 m – Data Mar 10 '15 at 19:56
  • 1
    You can view it. Type o.__proto__ - you won't get undefined. Is this related to an actual difficulty you are having? – barry-johnson Mar 10 '15 at 19:57
  • @Data seems @JLRishe right, if you try with simple custom object like `function A(){}` and `var a = new A()` you get same result, i mean _object expandable when it has properties_ – Grundy Mar 10 '15 at 19:58
  • Just tried in firefox and it works, I can see __proto __ (see edit 3). – Data Mar 10 '15 at 20:00
  • 1
    Is this an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)? Is there a reason you need to see the `__proto__` on empty objects? – JLRishe Mar 10 '15 at 20:02
  • @barry-johnson - Nope, it doesn't show __proto __, I have to add a function. It still doesn't show if I add a simple property like a:3 – Data Mar 10 '15 at 20:03
  • By "show" you mean "automatically display inline," which is not what I said. Are you saying that typing "o={}; o.__proto__" gives "undefined"? – barry-johnson Mar 10 '15 at 20:06
  • For those asking why I need to see __proto __, it's because I'm learning prototypal inheritance and I like to see what's 'under the hood'. – Data Mar 10 '15 at 20:06

1 Answers1

2

Who knows? It appears to be a design decision on the part of the Chrome debugger's implementers. Unless someone here is privy to their decision process, I think this question is off topic.

Perhaps they figured that you didn't need to be able to expand objects unless they have methods.

Both IE and Firefox show the __proto__ property in their console, even on empty objects. If you want to observe object prototypes for learning purposes, perhaps it would be better to do so in one of those browsers.

JLRishe
  • 99,490
  • 19
  • 131
  • 169
  • Off-topic from what? Being able to view the prototype chain in a debugger are two sides of the same coin. – Data Mar 10 '15 at 20:04
  • 2
    @Data Off-topic for Stack Overflow. On-topic questions are about how to solve practical programming problems, not about why some library/product/language designer who's not here made a particular design decision. I don't know what you're trying to say with your "two sides of the same coin" analogy. You seem to have only named one side. – JLRishe Mar 10 '15 at 20:05
  • I now understand it's a Chrome issue, so my bad for not checking FF, but to question the validity of the scope of my OP seems unreasonable; is there a flow-chart I should follow to ascertain if I'm allowed to ask a question? – Data Mar 10 '15 at 20:11
  • @Data [What topics can I ask about here?](http://stackoverflow.com/help/on-topic) is a good place to start. I would also advise reading that XY problem question. Your question could have been presented in an on-topic fashion if you had told us (a) What browser you were using. (b) Why being able to access an empty object's `__proto__` mattered to you, and phrased it as a solvable problem ("How can I view the `__proto__` on empty objects?") – JLRishe Mar 10 '15 at 20:16
  • Thanks for the link; it seems contradictory to state that I can ask about 'software tools commonly used by programmers', but then states off-topic as 'Questions seeking debugging help'...circular reference => stack overflow. I'll try to be more vigilant for future questions. – Data Mar 10 '15 at 20:26
  • @Data It doesn't state "Questions seeking debugging help" as off-topic. You just stopped reading after the first five words. This site is all about debugging help. – JLRishe Mar 10 '15 at 20:27
  • You're correct, 'twas a cursory glance; the end justifies your concerns: 'Questions without a clear problem statement are not useful to other readers'. But in my defence, I didn't know it was a Chrome issue at the time of posting, I thought it was a JS idiosyncrasy. Thanks again for keeping me in check, I'll mark your answer. – Data Mar 10 '15 at 20:31