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

156
Views
Ayúdame a entender el código en el método "handleEvent" a continuación en Javascript

 < button id = "elem" > Click me < /button> < script > class Menu { handleEvent(event) { // mousedown -> onMousedown let method = 'on' + event.type[0].toUpperCase() + event.type.slice(1); this[method](event); } onMousedown() { elem.innerHTML = "Mouse button pressed"; } onMouseup() { elem.innerHTML += "...and released."; } } let menu = new Menu(); elem.addEventListener('mousedown', menu); elem.addEventListener('mouseup', menu); < /script>

¿Podría alguien ayudarme a entender qué sucede en esta sección del código? Gracias.

 handleEvent(event) { // mousedown -> onMousedown let method = 'on' + event.type[0].toUpperCase() + event.type.slice(1); this[method](event); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

event.type[0].toUpperCase() -- this will return first character of your event name in upper case.(eg for submit event, it will return `S` ) event.type.slice(1) -- this will return you all characters of event name except first character. (eg for submit event , it will return `ubmit`)

Entonces estás concatenando arriba con on .

Después de eso, en la última línea de la función, está llamando a la función derivada que generó a partir de la cadena anterior, por ejemplo onSubmit .

En su caso, parece que está capturando el evento mousedown y luego convirtiendo ese evento en una cadena onMousedown() y llamando a su método onMousedown() .

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