I have this simple example with a class with a setInterval that calls main() every 5 seconds. When it comes to call print() it returns me TypeError: this.print is not a function. And I'm really stuck. Why if I call main() without setInterval it works smoothly but with setInterval it fails? It's weird. Any workaround to call main() periodically without this issue?
"use strict";
class test {
constructor() {
this.interval = setInterval(this.main, 5000);
}
print(){
console.log('Teeeessssttt');
}
main(){
this.print();
}
}
const a = new test();