Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

275
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda