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

315
Views
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 4 years ago · Santiago Gelvez
1 answers
Answer question

0

You need to call the function in window scope.

run(){
    this.s = "function teste() {console.log('testando')}"
    eval(this.s)
    
    window.teste();
  }
about 4 years ago · Santiago Gelvez 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!