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

169
Visualizações
Javascript method/shorthand that is used to control HTML video elements

Earlier I was following a tutorial about building a custom HTML video player. It's pretty basic but that tutorial indroduced some kind of shorthand in javascript to access the video element. Just curious about it.

So let's say, this is my video element:

<video class="viewer" src="652333414.mp4"></video>

Here is how I get the element and have a function to change state of the element

const video = document.querySelector(".viewer");

function togglePlay(){
    const method = video.paused ? 'play' : 'pause';
    video[method]();

    console.log(video[method]());
}

I understand video.paused is used to determine the video playing state. And the method variable gets the method name (string) which we want to execute. Now check this line video[method]();, I am curious about this syntax/shorthand/method.

By the way, it returns a promise.

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