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

110
Views
JavaScript | Haga clic en Evento | Declarar de diferentes maneras

Consulte el fragmento de código. No tiene nada que ver con el concepto del acelerador.

Declaro un evento de clic como btn.addEventListener("click", outerFunction); . Se invoca, pero la declaración 'console.log ("se hace clic en el botón de la función externa" + e.pointerType)' no se ejecuta.

Mientras que si declaro la función en línea, entonces funciona como se esperaba.

Entonces no puedo entender por qué no funciona cuando se declara en outerfunction

 const btn = document.querySelector("#throttle"); const btn2=document.querySelector("#newthrottle"); // Throttling Function const throttleFunction = (func, delay) => { // Previously called time of the function let prev = 0; return (...args) => { // Current called time of the function let now = new Date().getTime(); // Logging the difference between previously // called and current called timings console.log(now - prev, delay); // If difference is greater than delay call // the function again. if (now - prev > delay) { prev = now; // "..." is the spread operator here // returning the function with the // array of arguments //debugging arguments var inputArguments = [...args] console.log("arguments" + inputArguments); return func(...args); } }; }; function outerFunction(e) { console.log('Outer function') throttleFunction(((e)=>{ console.log("button is clicked outer function " + e.pointerType) }),1500) } //this does not work btn.addEventListener("click", outerFunction); //this works like a charm btn.addEventListener("click", throttleFunction((event)=>{ console.log("button is clicked throttle " + event.pointerType) }, 1500)); function onButtonClick(e){ console.log('Hello World onbutton Click' + e); } btn2.addEventListener("click", onButtonClick);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puedes hacer algo como esto -

 function outerFunction(e) { console.log('Outer function') const t = throttleFunction((e)=>{ console.log("button is clicked outer function " + e.pointerType) },1500); t(); }

Pero no estará definido, así que en lugar de devolver una función anónima, intente llamar a la función de devolución de llamada.

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!