Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!