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

155
Vistas
Undefined value in class method though it ís correctly set in constructor

The following is a snippet from Node.js. No Babel installed, nor will my employer do so in case that was gonna be a suggestion :)

I simplified a class to see what the issue might be, but I'm totally stuck. 2 files, 1 class.

index.js

const SESSION = 'bla bla';
const VARS = 'abc';

const Helper = require('./helper');

const helpertest = new Helper(SESSION, VARS);
const x = Helper.setProduct();

console.log('End result :', x);

helper.js

module.exports = class Helper {

    constructor(SESSION, VARS) {
        this.SESSION = SESSION;
        this.VARS = VARS;
        console.log('Hi session', this.SESSION, this.VARS); // Hi session bla bla abc
    }

    static get SESSION() {
        return this.SESSION;
    }

    static setProduct() {

        console.log('Hi setProduct', SESSION); // Uncaught ReferenceError: SESSION is not defined

    }
}

The issue is passing the SESSION to this function

static setProduct() {
    
            console.log('Hi setProduct', SESSION); // Uncaught ReferenceError: SESSION is not defined
    
        }

I have tried: this.SESSION, session, session() etc. etc.

No idea why it shows up correctly in the constructor and not in my method where i actually need it.

Please hand me some advise. Thanks in advance.

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

0

I suppose SESSION is an instance member and cannot be accessed from a static context.

You could try not using static when defining get SESSION() and setProduct.

You call would then look like helpertest.setProduct... instead of Helper.setProduct....

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