Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda