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

158
Views
Valor indefinido en el método de clase aunque está configurado correctamente en el constructor

El siguiente es un fragmento de Node.js. No se instaló Babel, ni mi empleador lo hará en caso de que fuera una sugerencia :)

Simplifiqué una clase para ver cuál podría ser el problema, pero estoy totalmente atascado. 2 archivos, 1 clase.

índice.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);

ayudante.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 } }

El problema es pasar la SESIÓN a esta función.

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

Lo he intentado: this.SESSION, session, session() etc. etc.

No tengo idea de por qué aparece correctamente en el constructor y no en mi método donde realmente lo necesito.

Por favor dame algunos consejos. Gracias por adelantado.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Supongo que SESSION es un miembro de instancia y no se puede acceder desde un contexto static .

Podría intentar no usar static al definir get SESSION() y setProduct .

Su llamada se vería como helpertest.setProduct... en lugar de 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!