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

136
Visualizações
Where is timerID coming from?

I'm halfway to understanding how this.timerId doesn't cause an error in the react docs.

class Clock extends React.Component {
  constructor(props) {
    super(props);
    this.state = {date: new Date()};
  }

  componentDidMount() {
    this.timerID = setInterval(
      () => this.tick(),
      1000
    );
  }

  componentWillUnmount() {
    clearInterval(this.timerID);
  }

  tick() {    this.setState({      date: new Date()    });  }
  render() {
    return (
      <div>
        <h1>Hello, world!</h1>
        <h2>It is {this.state.date.toLocaleTimeString()}.</h2>
      </div>
    );
  }
}

ReactDOM.render(
  <Clock />,
  document.getElementById('root')
);

I get that timerId along with setInterval come from Node. I thought node was just the runtime, does it come with other modules aside from Node Timers? Where is timerID initialized and or inherited from? Do all objects get a timerID when running on Node?

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

0

this.timerID in this case is created as a new property at the point that it is assigned a Value, as pointed out by @luk2302 in the comments.

Below shows another possible way you could refer to a property that wasn't created in that class directly, but in the parent class.

class SuperClass {
    constructor() {
        this.superProperty = "Hello I'm super!"
    }
}

class SupportClass extends SuperClass{
    constructor(example) {
        super();
        this.example = example;
    }

    supportMethod() {
        console.log(this.example);
        console.log(this.superProperty);
    }

}

let supportClass = new SupportClass("HELLO");

supportClass.supportMethod();

this produces an output:

HELLO
Hello I'm super!
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