I have a code for this function. I started learn js classes, and I want to remake this function into class. but I don't understand how to set start and remaining value into constructor correctly. also i don't understand how pass callback function into class
function Timer(callback, delay) {
/* privates properties */
let timerId, start, remaining = delay;
/* Public methods */
this.resume = () => {
start = new Date();
timerId = setTimeout( () => {
remaining = delay;
this.resume();
callback();
}, remaining);
};
this.pause = () => {
clearTimeout(timerId);
remaining -= new Date() - start;
};
this.become = () => {
clearTimeout(timerId);
remaining = delay;
this.resume();
};
/* Constructor */
this.resume();
}
I want to get a class identical to this function