Created
October 26, 2015 23:34
-
-
Save balanza/8ebebeb4a0310e966f49 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| //click count | |
| var count = 0; | |
| //this is the handler | |
| var onClick = function(e){ | |
| alert('button clicked ' + (++count) + ' times'); | |
| }; | |
| //this is the "throttled" function, | |
| // that is a function that executes only once in a given timespan (here: 200ms) | |
| var throttled = _.throttle(onClick, 200); | |
| //here the handler is bound to the event | |
| document.getElementById("myBtn").addEventListener("click", throttled); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment