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

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