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

144
Vistas
how to pass parameter from one page function to another page class function in Javascript / Node js

I want to pass parameter from my app.js page to another page User.js which contain class function but all I am getting is undefined value. I am trying to pass selected choice from the inqurier but its not getting passed.

User.js

class User{
  setUser(name){
    let userThing= fname(name);
    ...
    ...
    return userThing
  }

  getUser(){
    ...
    ...
    return
  }
}

module.exports.User=User;

app.js

const { Command } = require("@oclif/command");
const inquirer = require("inquirer");
const config = require("./User.js");

class RegionCommand extends Command {
 async run(){
   inquirer
   .prompt({
      type: "list",
      name: "test",
      message: " Select Nickname: ",
      default: false,
      choices: ["Tom", "Jerry"],
      })
      .then((answers) => {
        var selectedName=answers.test;
        // var nameDetails= this.config.User.setUser(selectedName); I tried this method too but still not working.
        var nameDetails= config.User.setUser(selectedName);
      });
 }
}

how can I pass my inqurier value app.js to user.js ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are trying to call a normal function like a static function. You first need to make a class instance!

const { Command } = require("@oclif/command");
const inquirer = require("inquirer");
const { User } = require("./User.js");

class RegionCommand extends Command {
 async run(){
   inquirer
   .prompt({
      type: "list",
      name: "test",
      message: " Select Nickname: ",
      default: false,
      choices: ["Tom", "Jerry"],
      })
      .then((answers) => {
        var selectedName=answers.test;
        const user = new User(); // create an instance of the class "User"
        var nameDetails= user.setUser(selectedName);
      });
 }
}
about 4 years ago · Juan Pablo Isaza Denunciar
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