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

180
Visualizações
Can't clearInterval when setInterval is set in an object

I'm having trouble stoping the interval with clearInterval when the value reaches 100. It reaches a 100 and then keeps on executing the setInterval. Can anybody tell me what i'm doing wrong? Appreciate for your help.

i've provided a link to jsfiddle. Open console.log to see the incrementation. https://jsfiddle.net/netzsqx4/

let values = [[]]
let Circle_1 = {
  procent:values[0][0],
  startFrom:0,
  incrementBy:0,
  start: null,
  intervalIdAtStart: function(){this.start= setInterval(function(){drawCircle.call(Circle_1)},500)},
  clear: function() {
    clearInterval(this.start);
  }

}


function drawCircle(inputValues){  
    if(this.startFrom<this.procent){
        console.log('draw <', this.procent + "     " + this.startFrom)
    this.startFrom++
    }
    else if(this.startFrom>this.procent){
        console.log('draw >', this.procent + "     " + this.startFrom)
      this.startFrom--
    }
    else{
        console.log('else', this.procent + "     " + this.startFrom)
        this.clear;
    }
  };


  function Http(){
    
    let output = 100
    loadoutput(output)

    function loadoutput(input){

        console.log(input)
        
        values = [
            [input], 
        ]

        Circle_1.procent=values[0][0]
        Circle_1.intervalIdAtStart()
    }
  }

function getValues(){
  Http();
}

  setTimeout(getValues,1000);

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

0

It was this.clear but it should be this.clear(). This resolved my problem.

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