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

377
Views
Unable to have get and set method in Object Constructor (not in class) in JavaScript?

When creating simple Object literal we can easily have get/set method.

const John = {
  firstName: "John",
  lastName: "Doe",
  teach: "Physics",
  language: "en",
  get lang() {
    return this.teach;
  }
};

John.teach //isValid

But what if we want to define get/set in Object Constructor. (Not Class one). I tried this way but it's not working...

    function Faculties (fName,lName,teach,lang){
      this.firstName = fName;
      this.lastName = lName;
      this.teach = teach;
      this.language = lang;
      get this.lang() = function(){
        return this.teach
    }
  }

any help would be appreciated..thank uh

about 4 years ago · Juan Pablo Isaza
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!