function Figure() {
...
this.interval = setInterval( this.swing );
...
}
var fig = new Figure();
fig = null;
preapreDestroy
:class Some {
constructor() {
this.interval = setInterval(this.method, 100);
}
method() {
console.log(`Date.now: ${Date.now()}`);
}
prepareDestroy() {
clearInterval(this.interval);
}
}
const sleep = duration => new Promise(resolve => setTimeout(resolve, duration));
(async () => {
let some = new Some();
await sleep(3000);
some.prepareDestroy();
some = null;
})();
setInterval
на requestAnimationFrame