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();
You need to call the function in window scope.
run(){
this.s = "function teste() {console.log('testando')}"
eval(this.s)
window.teste();
}