为什么attr从dom中的节点继承?

发布于 2025-01-24 16:21:19 字数 763 浏览 2 评论 0原文

根据 dom core

attr对象继承了节点接口,但是由于它们实际上不是它们描述的元素的子节点,因此DOM不认为它们是文档树的一部分。

还有

dom采取的视图是属性是元素的属性,而不是与

相关联的元素具有单独的身份

与此相关联的元素中具有单独的身份,什么是attry attry 对象的优势。 >?

dom spec 状态:

出于历史原因,

attrynodes参加了一棵树;他们从来没有(非无效)父母或任何孩子,因此独自一人在树上。

这是一个部分答案,但是我想知道是否有人对attry's 节点继承和树的参与更深入地解释,而不是简单的“历史原因”。

抱歉,如果这是一个重复的问题,我发现的大多数问题都围绕attry对象的行为,而不是其结构背后的基本原理。

according to the DOM Core,

Attr objects inherit the Node interface, but since they are not actually child nodes of the element they describe, the DOM does not consider them part of the document tree.

and also

The DOM takes the view that attributes are properties of elements rather than having a separate identity from the elements they are associated with

Given this, what is the advantage of Attr objects inheriting from Node?

The DOM Spec states:

Attr nodes participate in a tree for historical reasons; they never have a (non-null) parent or any children and are therefore alone in a tree.

which is a partial answer, but I'm wondering if anyone has any deeper explination of Attr's Node inheritance and tree participation than simply "historical reasons".

Sorry if this is a duplicate question, most questions I've found revolve around the behavior of Attr objects, rather than the rationale behind their structure.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡笑忘祈一世凡恋 2025-01-31 16:21:19

有了一个“为什么”问题,您需要非常清楚您是否在问

  • 该决定的潜在好处是什么?或

在大多数情况下,第二个问题是无法回答的,尽管在少数情况下(例如Tim Bray的注释XML规范),您至少可以看到其中一位编辑提出的理由。

对我来说,这个决定感觉就像是妥协。属性与其他节点具有许多共同的属性,因此使它们实现相同的接口有一个优势。但是,您并不真正想要的行李,因为它可能会增加不必要的成本,例如拥有指定元素的链接。

坦率地说,DOM不是一个不错的设计,很难说为什么它犯了这么多的设计错误,除了急切的委员会将其放在一起。后来的JOND和XOM等模型要好得多,但可悲的是JavaScript。

With a "why" question, you need to be very clear whether you are asking

  • what are the potential benefits of this decision?, or

  • historically, what arguments were put forward and why did individual committee members vote the way they did (if indeed there was a discussion and a vote)?

In most cases the second question is unanswerable, though in a few cases (such as the Annotated XML specification by Tim Bray) you can at least see the rationale put forward by one of the editors.

To me the decision feels like a compromise. Attributes have many properties in common with other nodes, so there's an advantage in having them implement the same interface; but there's baggage that you don't really want because it might add unnecessary cost, like having a link to the containing element.

Frankly, DOM is not a good piece of design, and it's very hard to say why it made so many design mistakes, other than that it was put together by a committee in a hurry. Later models such as JDOM and XOM are much better, but sadly not available for Javascript.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文