Last active
February 1, 2021 07:29
-
-
Save tit/1e7051f6b9b80b96fc4fdee5e41f250a to your computer and use it in GitHub Desktop.
Create AntiFool Button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setSensitivity(element: HTMLElement, callback: () => void, timeout: number = 500): void { | |
let sensitivityTimer: number; | |
element | |
.addEventListener('mousedown', () => { | |
sensitivityTimer = setTimeout(callback, timeout); | |
}); | |
element | |
.addEventListener('mouseup', () => { | |
clearTimeout(sensitivityTimer); | |
}); | |
} |
You could pass callback to setTimeout without wrapping it into additional arrow function (since callback is already a function)
sensitivityTimer = setTimeout(callback, timeout)
Thanks! You're right, I overdid it a bit. Made changes.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could pass callback to setTimeout without wrapping it into additional arrow function (since callback is already a function)
sensitivityTimer = setTimeout(callback, timeout)
Overall LGTM