[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

the interface "Document"

ram

1/9/2016 7:19:00 PM

The web page at »developer.mozilla.org/en-US/docs/Web/API/Document«
says: »

This interface also inherits from the Node and EventTarget interfaces.
....
The Document interface is extended with the ParentNode interface

«. What is the difference between »to inherit from« and
»to be extended with«?

The web page at »www.w3.org/TR/dom/« says: »

interface Document : Node {

«. Why does it not mention »EventTarget« nor »ParentNode«?

Ok, possibly »EventTarget« is out of the scope of the DOM.
But what about »ParentNode«?

Later »www.w3.org/TR/dom/« says in the section of »ParentNode«: »

Document implements ParentNode

«. Why is »Node« mentioned prominently in the documentation
of »Document«, but »ParentNode« is not mentioned at all in
the documentation of »Document« in »www.w3.org/TR/dom/«?

Why can't they just write: »

interface Document : Node, ParentNode

«? Is their IDL restricted to single inheritance?

3 Answers

ram

1/10/2016 12:20:00 AM

0

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>Is their IDL restricted to single inheritance?

The DOM4-IDL seems to have inherited (no pun intended)
single inheritance from JavaScript.

ram

1/10/2016 11:02:00 PM

0

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>ram@zedat.fu-berlin.de (Stefan Ram) writes:
>>Is their IDL restricted to single inheritance?
>The DOM4-IDL seems to have inherited (no pun intended)
>single inheritance from JavaScript.

I would like to show in my course that »Document« is a
»subclass« (using a term from the Java world) of »Node«.
I could do this as follows:

|< new Document instanceof Node
|> true

, but at that point in my course, I have not yet introduced »new«.

I could show them this (calls and the dot notation were
already explained):

|< Object.getPrototypeOf( Document.prototype ).constructor.name
|> "Node"

, but this would still be too complicated at this point in
the course, and I also have not yet explained prototypes nor
constructors at this point.

Sigh, so I am afraid, there is no way to show this that only
uses calls, dot notation, and operators, and is small and
easy as »new Document instanceof Node«?

Thomas 'PointedEars' Lahn

1/11/2016 12:23:00 AM

0

Stefan Ram wrote:

> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>>ram@zedat.fu-berlin.de (Stefan Ram) writes:
>>>Is their IDL restricted to single inheritance?
>>The DOM4-IDL seems to have inherited (no pun intended)
>>single inheritance from JavaScript.

Nonsense. Instead, the fact that DOM interfaces should be language-neutral
makes it a bad idea to specify them using multiple inheritance as that is
not supported by all object-oriented programming languages; most notably,
not by ECMAScript implementations.

> I would like to show in my course that »Document« is a
> »subclass« (using a term from the Java world) of »Node«.

Donâ??t. DOM interfaces are *language-neutral*. The proper language-neutral
wording is that one interface extends another.

> I could do this as follows:
>
> |< new Document instanceof Node
> |> true

Where? Not in WebKit/Blink:

| > new Document instanceof Node
| Uncaught TypeError: Illegal constructor(â?¦)

> , but at that point in my course, I have not yet introduced »new«.

You should refrain from giving courses until you got the basics yourself.
Enough nonsense is being disseminated in this field already, by books, and
clueless talks, blog and forum posts.

> I could show them this (calls and the dot notation were
> already explained):
>
> |< Object.getPrototypeOf( Document.prototype ).constructor.name
> |> "Node"
>
> , but this would still be too complicated at this point in
> the course,

It would also be wrong. The implementation of â??Documentâ? and â??Nodeâ?
interfaces does _not_ imply the existence of objects referrable with
â??Documentâ? and â??Nodeâ?, that those are objects that can be called as
constructors, or that they have a â??prototypeâ? property.

> Sigh, so I am afraid, there is no way to show this that only
> uses calls, dot notation, and operators, and is small and
> easy as »new Document instanceof Node«?

No, there is.

It stands to reason that the object referred to by the host-defined
â??documentâ? property of the global object (the â??documentâ? object) would be
constructed (internally) using that interface. And so in Blink (Chromium
46):

document.constructor.name === "HTMLDocument"
document instanceof HTMLDocument === true
document instanceof Document === true
document instanceof Node === true

In order to establish the inheritance hierarchy without that, one only needs
to show that the â??documentâ? object has properties that are implementations
of attributes of different DOM interfaces that are specified to extend each
other.

--
PointedEars
FAQ: <http://PointedEars.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not cc me. / Bitte keine Kopien per E-Mail.