Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

test () {
   return this.text;
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda