为什么当JS不进行时,为什么DOM面向对象结构?
在DOM(HTML解析文件的js rappresentation)中,我们具有此结构(其中< 用于“ senasented ”):
Object(JS object) < Node < Element < HTMLElment < HTMLBodyElement, HTMLDivElement, etc..
Object(JS object) < Node < DOcument < HTMLDocument
...
所有这些节点均称为接口( https://develper..mozilla.mozilla.org/en-us/en-us/docs/web/api/ htmlelement )在我检查的每个文档中。
我不明白JS中的这种情况如何(不是面向对象,没有接口等)?我有C ++的背景,因此也许我将DOM“面向对象”的结构与真实的结构混淆。有澄清吗?
In DOM (JS rappresentation of HTML parsed file) we have this structure(where < is for "inherited"):
Object(JS object) < Node < Element < HTMLElment < HTMLBodyElement, HTMLDivElement, etc..
Object(JS object) < Node < DOcument < HTMLDocument
...
All these nodes are called interfaces (https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement) in every documentation I have checked.
I don't understand how is this possible in JS (not object-oriented, no interfaces, etc)? I have a background in C++, so maybe I am confusing DOM "object-oriented" structure with a real one. Any clarification?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在JavaScript中建模DOM的结构没有问题。 JavaScript 非常面向对象,包括支持继承。 javaScript使用原型遗传。例子:
JavaScript还覆盖了似乎的原型继承之上的东西,而是
class
like(不是,它仍然是典型的,但是对于来自基于类的人来说,它更舒适语言)。例如,这是一个三层继承模型(类似于node
&lt;element
&lt;htmlelement
)使用class> >语法(但同样,我们也可以在没有
class
语法的情况下完成所有这些操作):(
对象
该结构的基础是隐式的。)There's no problem modelling the DOM's structure in JavaScript. JavaScript is very object-oriented, including supporting inheritance. JavaScript uses prototypical inheritance. Example:
JavaScript also overlays something on top of prototypical inheritance that seems rather
class
-like (it isn't, it's still prototypical, but it's more comfortable for people coming from class-based languages). For instance, here's a three-layer inheritance model (rather likeNode
<Element
<HTMLElement
) usingclass
syntax (but again, we could do all of this withoutclass
syntax, too):(The
Object
base of that structure is implicit.)