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

216
Vistas
How can I use observedAttributes to an anonymous class / function?

I want to register a custom element with an anonymous class / function. But I wonder how to use the observedAttributes to the object?

Class Version. How it works

<my-el name="abc"></my-el>
class MyEl extends HTMLElement {...}
MyEl.observedAttributes = ["name"];

Version anonymous class/ function. How it does not work

window.customElements.define("my-el", class extends HTMLElement {...});

// how i can bind now?
MyEl.observedAttributes() // throws an error: ReferenceError: MyEl is not defined 
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can define a static getter on your class expression like so, which is supported in ES2015 and above:

window.customElements.define("my-el", class extends HTMLElement {
  static get observedAttributes() {
    return ["name"];
  }
});

Otherwise, if you can support ES2022 and above, you can create a public static field (rather than a getter):

window.customElements.define("my-el", class extends HTMLElement {
  static observedAttributes = ["name"];
});
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