Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

279
Vistas
Receiver in Reflect.get() not working as expected

I wrote a proxy of HTMLAudioElement. When I call play() method via the proxy.

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

I got a Error:

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

As far as I know, it is because that the play function is not bind to target. However, Shouldn't the prop receiver do the binding for us? Or something wrong in my code?

Then, I have to change my code as below, it looks weired, but works.

   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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda