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

153
Views
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 answers
Answer question

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 Report
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!