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

291
Visualizações
Eventlistener function is undefined?

When a button is clicked I want the event listener to be removed.

function clickMe(f,i){
      ipcRenderer.send('click', i)

      ipcRenderer.on(`message`, function (en, message) {
        document.getElementById(`status${i}`).innerHTML = message[1];
        //ipcRenderer.removeAllListeners('message') <- I don't want all listeners to be removed
      });
}

As shown in the code above, removeAllListeners works, however, I do not want all listeners to be removed. I believe I can use removeListener('message', function) but if I try to put removeListener('message', startMe()) I get thrown an error of undefined. How would I go abouts doing this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The method is called removeEventListener which takes the function you want to remove as its second parameter. You can't remove it, because the function is anonymous. If you use named functions, it should work:

function onMessage = function (en, message) {
    document.getElementById(`status${i}`).innerHTML = message[1];
    ipcRenderer.removeEventListener('message', onMessage);
}

function clickMe(f,i){
      ipcRenderer.send('click', i)
      ipcRenderer.on('message', onMessage);
}
about 4 years ago · Juan Pablo Isaza Relatório
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