Consider this:
class ConnectUser {
connect = () => {
axios.get('URL').catch(err => {
// CAN I CALL `connect` METHOD AGAIN?!
// this.connect();
});
}
}
My code has a method and can connect or refuse to connect to some resources. If an exception happens can I call it again to strive for connecting?
Yes, you can. But if this is something you want to generalize on your app, consider using an axios plugin that automatically retries and only fails after the amount of retries you specify. You can call just connect function again if you define it as a separate function on the scope instead of a class method. But if you really need to call using this, save the proper this reference in the outer closure like this:
connect = () => {
const self = this
axios.get('URL').catch(err => {
self.connect();
});
}
Then use self instead