Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

280
Vistas
Why is Comment an interface/class?

I'm a beginner in web development so I was reading MDN Web Docs and Chromium source code in order to understand how Javascript DOM HTML element classes work and are implemented and I found out that HTML comment elements are actually interfaces/classes (i don't know why in MDN it's called an interface if it has a constructor) (https://developer.mozilla.org/en-US/docs/Web/API/Comment). Why is it made that way? Isn't it a waste of space?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Unlike in many languages, HTML comments are part of the mark-up. You can dynamically generate them and insert them into the DOM, just like you can do with any other node.

This can potentially be useful, for example, by libraries which modify the DOM but wish to preserve comments for readability purposes. Some frameworks actually use comments to help them keep track of different nodes or lists of nodes.

Here's an example of how you might dynamically generate a comment within the HTML of a webpage. if you run these two lines in any webpage, you'll find a new <!-- Hello World! --> comment at the bottom of the body element:

const myComment = new Comment('Hello World!')
document.body.appendChild(myComment)

The ability to preserve comments actually isn't unique to HTML, other markup-parsing libraries will provide you with this kind of ability, precisely for the purposes of preserving them as you dynamically modify the markup. For example, see this yaml parser, which will automatically preserve the comments for you as it parses.

about 4 years ago · Juan Pablo Isaza Denunciar

0

The "interface" (of a comment node) being referred to is the description of its properties methods and/or nature provided using IDL ("interface definition language") within a specification. In other words "interface" as used here means "what it exposes, if anything" and, by implication, how it works.

Be wary of interpreting "interface" in the context of an IDL definition in the context of a programming language - the whole idea of IDL is to allow specifications to be written independently of specific programming languages.

You can read the specification of the comment interface in the DOM3 specification here.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda