0

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

0 Answers0