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

140
Vistas
How do you name an event handler whose subject has a long name, in JavaScript and its libraries and frameworks?

By convention, the name of the event handler as an attribute of a component should comply with that of an HTML tag, e.g. onTextChange, following the pattern onSubjectEvent, while the specific function that acts as the event handler should have a name with the pattern handleSubjectEvent. Here the "Event" is just the simple form (e.g. Change) of a verb, not a past participle (Changed) or a present participle (Changing). This convention is easy to follow when the subject has a short name. However, there are many occasions when the subject name is long due to a long modifier as we would like to make the name as self-explained as possible.

E.g., complying with the HTML convention, onNameAdd and handleNameAdd look fine, but onOverseasSuppliersLegalNameAdd and handleOverseasSuppliersLegalNameAdd look unbalanced. I've seen some developers who are native English speakers name the handler as onAddOverseasSuppliersLegalName, following a onEventSubject pattern. And some of them even stick to this pattern when the subject name is short, like onAddName, which contradicts the HTML convention.

I have searched for this issue, but people are only talking about the case of a short subject name, so I was wondering how you would name an event handler when the subject name is short and long, respectively.

  1. Strictly follow the HTML convention. E.g. onNameAdd & onOverseasSuppliersLegalNameAdd

  2. Put the event name (or the verb) between on/handle and the subject to avoid an unbalanced handler name when the subject name is long. E.g. onAddName & onAddOverseasSuppliersLegalName

  3. It depends on the length of the subject name. When it's short, follow the HTML convention; when it's long, put the verb in the middle. E.g. onNameAdd & onAddOverseasSuppliersLegalName

about 4 years ago · Juan Pablo Isaza
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