I have made a class Service. I am trying to run a Interval every X seconds. The default is 30 seconds. But I want to set a custom delay if needed in other classes. I can't find a way to override the variables in my parent class.
class Service {
delay = 30;
constructor(api, client = undefined) {
this.api = api;
this.client = client;
this.handle();
}
getMiliSeconds() {
return this.delay * 1000;
}
service = async () => {
// Service to run in background
}
handle() {
setInterval(() => { this.service() }, this.getMiliSeconds());
}
}
module.exports = Service;
When I extend the class Service I am trying to override the delay variable
class Notification extends Service {
delay = 60;
service = async () => {
// I am not running every 60 seconds.
}
}
module.exports.Notification = Notification;
However the Interval function is still runned every 30 seconds. Instead of the 60 seconds I set in the Notifications class.
let services = [new Notification(api, client), new Receiver(api, client)];