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

162
Visualizações
How to call getter and setter from within a javascript class

Is it possible to call getter and setter from within own class ? If yes what's the valid syntax instead of invalid

  this.gettext();

in below class :

  class Test {

    _text: string;
    constructor(value: string) {
      this._text = value;
    }

    get text() {
      return this._text;
    }

    set text(value) {
      this._text = value;
    }

    test () {
      return this.gettext();
    }
  }
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Setters are called during asignment and getters during reading.

  this.text = "testing..."

will call the setter passing "testing..." as a value.

  console.log(this.text)

will call the getter

If you need to treat as a callable method, wrap it inside a method or don't use properties (getters/setters), use a method instead. If, as you show, you want to wrap it in another method for some reason:

test() {
   return this.text;
}
about 4 years ago · Juan Pablo Isaza Relatório

0

test () {
   return this.text;
}
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