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

244
Vistas
What should the output of a JavaScript Class look like?

I am attempting to use inquirer to collect user input, that is turned into an object, it is then passed into a class constructor. Everything seems to working the way I want it to accept the resulting array of objects after they are passed though the classes come out in a way that is confusing me,

when I console.log the array that contains the objects that are returned by my classes this is what comes out:

[
  Manager {
    name: 'bob',
    id: '24',
    email: 'bob.com',
    officeNumber: '1'
  },
  Engineer {
    name: 'jack',
    id: '347',
    email: 'jack.com',
    github: 'jackolantern'
  },
  Intern {
    name: 'sally',
    id: '987',
    email: 'sally.com',
    school: 'UCF'
  }
]

Here is an example of one of the classes:

class Manager extends Employee {
  constructor (employeeObj) {
    super (employeeObj);
    this.name = employeeObj.name;
    this.id = employeeObj.id;
    this.email = employeeObj.email;
    this.officeNumber = employeeObj.officeNumber;

  }
  getOfficeNumber () {
    return this.officeNumber;
  }
  getRoll () {
    return "Manager";
  }
}
module.exports = Manager;

and this is how the objects are passed into the classes:

const prompts = async () => {
  let employeeObj = {};
  const employee = await inquirer.prompt(addEmployee);

    switch(employee.addEmployee){
      
      case 'Manager':
       employeeObj = await managerQuestions();
      const manager = new Manager(employeeObj);
        output.push(manager);
        if(employeeObj.addAnother){
          return prompts();
        } else {
          complete();
        }
        break;

      case 'Engineer':
       employeeObj = await engineerQuestions();
        const engineer = new Engineer(employeeObj)
        output.push(engineer)
        if(employeeObj.addAnother){
          return prompts();
        } else {
          complete();
        }
        break;

      case 'Intern':
        employeeObj = await internQuestions();
        const intern = new Intern(employeeObj)
        output.push(intern)
        if(employeeObj.addAnother){
          return prompts();
        } else {
          complete();
        }
        break;

      default:
        console.log('you have reached the default switch statement. thant should not happen. Please try again!');
      }
  }

what I cant seem to figure out, is why the "roll" for each object (Manager, Engineer, Intern) is being placed outside the corresponding object and not inside it. I was able to add a this.roll = "manager" inside the constructor and as expected it added in a property called roll with a value of "manager" which will work just fine for what I need to do, but how do I get rid of that Manager, Engineer, and Intern that shows up before each object in the output array, or can it be moved inside the object?

thank you for taking the time to read through all this.

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