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

6.1K
Views
¿Para qué sirve 'savedThis' en la solución Throttle decorador en javascript.info?

En https://javascript.info/call-apply-decorators , se encuentra la solución para la tarea del decorador Throttling. Modifiqué el código para deshacerme de 'sevedThis' y funciona perfectamente sin él (incluso con métodos de objetos). ¿Alguien podría dar una razón real para usar la variable 'sevedThis' en este caso y llamar a 'wrapper.apply (savedThis, SavedArgs)' en lugar de 'wrapper (... savedArgs)'?

Codigo original:

 function throttle(func, ms) { let isThrottled = false, savedArgs, savedThis; function wrapper() { if (isThrottled) { // (2) savedArgs = arguments; savedThis = this; return; } isThrottled = true; func.apply(this, arguments); // (1) setTimeout(function() { isThrottled = false; // (3) if (savedArgs) { wrapper.apply(savedThis, savedArgs); savedArgs = savedThis = null; } }, ms); } return wrapper; }

Código sin 'savedThis':

 function throttle(func, ms) { let isThrottled = false, savedArgs; function wrapper() { if (isThrottled) { // (2) savedArgs = arguments; return; } func.apply(this, arguments); // (1) isThrottled = true; setTimeout(function () { isThrottled = false; // (3) if (savedArgs) { wrapper(...savedArgs); savedArgs = null; } }, ms); } return wrapper; }
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!