Node's __proto__

21 views
Skip to first unread message

Eric J. Van der Velden

unread,
Mar 11, 2012, 9:49:04 AM3/11/12
to
Hello,

What is Node.__proto__ , or Element.__proto__ ?

Thanks

Eric J.

Bobby Holley

unread,
Mar 12, 2012, 2:00:37 AM3/12/12
to Eric J. Van der Velden, dev-te...@lists.mozilla.org
Hi Eric,

|Node| and |Element| are both constructor objects. They both have the same
proto, and it's very uninteresting (the proto of that object is
Object.prototype).

Things like |Node| and |Element| are just kind of waystations on the way to
things like Node.prototype and Element.prototype. Those are the __proto__s
for actual Node and Element instances, and they form a nice inheritance
hierarchy (ie: Element.prototype.__proto__ === Node.prototype).

But we also do a lot of that stuff wrong in Gecko, as it stands. For
example, each prototype has a flattened version of all methods and
properties it inherits. But we're fixing this all soon.

Cheers,
bholley
> _______________________________________________
> dev-tech-dom mailing list
> dev-te...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-dom
>

Eric J. Van der Velden

unread,
Mar 16, 2012, 3:15:09 PM3/16/12
to
> > dev-tech-...@lists.mozilla.org
> >https://lists.mozilla.org/listinfo/dev-tech-dom

Hi Bobby,

Thank you very much for taking the effort to explain this to me.

I understand for example that
Node.prototype.__proto__===Object.prototype, but although
uninteresting, I still would like to know what I should write on
the ... in Node.__proto__===....prototype. I'll tell you why. I
thought I had it all figured out, but it apparently is not true.
Because Object is a function, Object.__proto__===Function.prototype.
So I thought: Function.__proto__===Function.prototype. I thought
Function in JavaScript similar to Object in Java. But it is not true.
So what is Function.__proto__, Node.__proto__, ...?

Also what do you mean by "each prototype has a flattened version of
all methods and properties it inherits"?

Thanks,

Eric J.

Boris Zbarsky

unread,
Mar 16, 2012, 3:30:31 PM3/16/12
to
On 3/16/12 3:15 PM, Eric J. Van der Velden wrote:
> I understand for example that
> Node.prototype.__proto__===Object.prototype, but although
> uninteresting, I still would like to know what I should write on
> the ... in Node.__proto__===....prototype.

Per future specs, Node.__proto__ === Function.prototype, since Node is a
Function object.

In Gecko's current implementation, it depends. In the new DOM bindings,
the interface object's proto should be Function.prototype. In the
XPConnect bindings (which Node is at the moment, but hopefully not for
much longer), I have no idea offhand.

> Because Object is a function, Object.__proto__===Function.prototype.
> So I thought: Function.__proto__===Function.prototype. I thought
> Function in JavaScript similar to Object in Java. But it is not true.

Function.__proto__ === Function.prototype, yes.

Node is special, because it's actually a host object at the moment.

> Also what do you mean by "each prototype has a flattened version of
> all methods and properties it inherits"?

That wasn't relevant to your question; it was about Node.prototype.

-Boris

Eric J. Van der Velden

unread,
Mar 18, 2012, 2:12:24 PM3/18/12
to
Hi Boris,

Thank you very much.

Function is defined in SpiderMonkey. Where is Node defined?

Thanks,

Eric J.

Boris Zbarsky

unread,
Mar 18, 2012, 8:53:44 PM3/18/12
to
On 3/18/12 2:12 PM, Eric J. Van der Velden wrote:
> Function is defined in SpiderMonkey. Where is Node defined?

You mean in terms of our implementation, or in terms of the specs?

-Boris
Reply all
Reply to author
Forward
0 new messages