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

273
Views
El receptor en Reflect.get() no funciona como se esperaba

Escribí un proxy de HTMLAudioElement. Cuando llamo al método play() a través del proxy.

 const proxy = new Proxy( audioPlayer, { get(target: typeof audioPlayer , prop, receiver) { return Reflect.get(target, prop, receiver); } }); proxy.play();

Recibí un error:

TypeError: Failed to execute 'play' on 'HTMLMediaElement': Illegal invocation

Hasta donde yo sé, es porque la función de play no está vinculada al target . Sin embargo, ¿no debería el receiver de utilería hacer el enlace por nosotros? ¿O hay algo mal en mi código?

Luego, tengo que cambiar mi código como se muestra a continuación, parece extraño, pero funciona.

 const proxy = new Proxy( audioPlayer, { get(target: typeof audioPlayer , prop, receiver) { if(prop=='play'){ return target.play.bind(target) }else if(prop=='pause'){ return target.pause.bind(target) } return Reflect.get(target, prop, receiver); } }); proxy.play();
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!