0

I want to write some javascript classes which inherit from the DOM Node interface... Sounds very much like how-to-inherit-from-the-dom-element-class, but I do not want to use its instances it in my [X|XHT|HT]ML document. My aim is to build a absolutely stand-alone DOM tree, so I would like to use the Node interface provided by modern browsers instead of creating my own DOM implementation. The nodes should not have any HTML attributes like classname, styles or (client)offsets - just a plain Node. The class doesn't need to be extensible, the Node methods would be enough.

I would also be happy if there was a possibility to create a DocumentFragment or a new Document which
a) is not a (X)HTML document but a XML document and
b) is not associated with the current document (as in document.implementation)

The script should work in the latest versions of Opera and Firefox. Other browsers are a nice-to-have, not a must; and I don't care about any old versions.

0

2 Answers 2

0

It seems to be that this is the closest to my requirements:

new DOMParser().parseFromString("<root />", "text/xml");

But still no way to inherit from the Node interface.

0

No. Node is an abstract interface. It does not have a constructor operation, which means that you can neither construct it nor inherit from it. It just throws:

Interface objects whose interfaces are not declared with a constructor operation will throw when called, both as a function and as a constructor.

So while you can write class Sub extends Node {}, you could never instantiate it. Similarly, inheriting from Node.prototype is possible but pointless since all the builtin methods require the internal fields.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.