有没有办法继承javascript Node接口?
我想编写一些从 DOM Node 接口继承的 javascript 类...听起来很像 如何从-dom-element-class继承,但我不想在我的 [X|XHT|HT]ML 文档中使用它的实例。我的目标是构建一个绝对独立的 DOM 树,所以我想使用 现代浏览器提供的 Node 接口,而不是创建我自己的 DOM 实现。节点不应具有任何 HTML 属性,例如类名、样式或(客户端)偏移量 - 只是一个普通的 Node。该类不需要可扩展,Node 方法就足够了。
如果有可能创建一个 DocumentFragment 或一个新文档,我也会很高兴
a) 不是 (X)HTML 文档而是 XML 文档并且
b) 与当前文档不关联(如 document.implementation 所示)
该脚本应该可以在最新版本的 Opera 和 Firefox 中运行。其他浏览器是可有可无的,而不是必须的;而且我不关心任何旧版本。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来这是最接近我的要求了:
但是仍然没有办法继承Node接口。
It seems to be that this is the closest to my requirements:
But still no way to inherit from the Node interface.
不。
Node
是一个抽象接口。它没有构造函数
操作,这意味着你既不能构造它也不能继承它。它只是抛出:因此,虽然您可以编写
class Sub extends Node {}
,但您永远无法实例化它。同样,从 Node.prototype 继承是可能的,但毫无意义,因为所有内置方法都需要内部字段。No.
Node
is an abstract interface. It does not have aconstructor
operation, which means that you can neither construct it nor inherit from it. It just throws:So while you can write
class Sub extends Node {}
, you could never instantiate it. Similarly, inheriting fromNode.prototype
is possible but pointless since all the builtin methods require the internal fields.