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

208
Views
Advertencia de JSHint sobre addEventListener "`Las funciones declaradas dentro de los bucles que hacen referencia a una variable de ámbito externo pueden conducir a una semántica confusa"

Estoy usando una función que hace que un botón en el que se hace clic esté en negrita mientras que sus otros botones hermanos tienen un peso de fuente normal. La función funciona correctamente, pero recibo una advertencia en JSHint que dice que las Functions declared within loops referencing an outer scoped variable may lead to confusing semantics. (gLength, buttonParent) . Intenté usar let en lugar de var en el código a continuación, pero la advertencia sigue ahí. ¿Cómo puedo solucionar el problema que muestra JSHint?

 function boldButton(buttonParent) { buttonParent = buttonParent.querySelectorAll("BUTTON"); if (buttonParent) { for (var g = 0, gLength = buttonParent.length; g < gLength; g++) { // set all buttons as normal font before setting a clicked button as bold font: buttonParent[g].addEventListener('click', function() { for (var r = 0; r < gLength; r++) { buttonParent[r].style.fontWeight = "normal"; } // set the clicked button as bold font: this.style.fontWeight = "bold"; }, false); } } } var buttonWrap = document.getElementById("button-wrap"); boldButton(buttonWrap);
 <div id="button-wrap"> <button>Button 1</button> <button>Button 2</button> <button>Button 3</button> </div>

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!