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

388
Vistas
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
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