Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
Cómo llamar a getter y setter desde dentro de una clase de javascript

¿Es posible llamar a getter y setter desde dentro de la propia clase? En caso afirmativo, ¿cuál es la sintaxis válida en lugar de inválida?

 this.gettext();

en la siguiente clase:

 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 answers
Answer question

0

Se llaman setters durante la asignación y getters durante la lectura.

 this.text = "testing..."

llamará al colocador que pasa "testing..." como un valor.

 console.log(this.text)

llamará al captador

Si necesita tratarlo como un método invocable, envuélvalo dentro de un método o no use propiedades (getters/setters), use un método en su lugar. Si, como muestra, desea envolverlo en otro método por algún motivo:

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

0

test () { return this.text; }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!