• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

274
Vistas
Nodejs Difficulty using eval inside class

I'm having trouble using eval in my js file (class).

When I develop a code globally it works (Ex 1).

Now when I use eval inside the class it doesn't work (Ex 2)

Code Ex 1 ->

var s = "function teste() {console.log('testando')}"
eval(s)

this.teste();

**Code Ex 2 -> **

class Oi {

  constructor() {
    this.s = ""
    this.t = ""
  }
  
  run(){
    this.s = "function teste() {console.log('testando')}"
    eval(this.s)
    
    this.teste();
  }
}

let o = new Oi();
o.run();
about 3 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

You need to call the function in window scope.

run(){
    this.s = "function teste() {console.log('testando')}"
    eval(this.s)
    
    window.teste();
  }
about 3 years ago · Santiago Gelvez 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda