I have the below code:
window.addEventListener('mousemove', ()=>{
myInterval = setTimeout(mouseMove, 2000);
});
const mouseMove = () => {
console.log('first console');
onMouseMove = (e) => console.log("mouse location:", e.x, e.y)
}
Only at the end of the timeout I should console.log the coordinates of the mouse; however, onMouseMove is not respecting the timeout logic.
The console.log('first console') is triggered only at the end of the 2 seconds, but onMouseMove triggers with every move of the mouse.
In addition to the above, I would like to console.log only the last coordinate at the end of this 2 seconds.
I've tried changing between setInterval and setTimeout, also clearing these interval and timeout, but still didnt work as intended.