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

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

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 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!