Last active
August 19, 2018 18:16
-
-
Save ldmarz/18d66de7e99ed65704ffa0ceb7ae8671 to your computer and use it in GitHub Desktop.
Example to Improve your javascript speed with throttle, example at: https://wp.me/pabITX-7j
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
// find elements | |
let i = 0; | |
function writeDOM() { | |
// Imagine some slow/hard function | |
$("#result").html(i++); | |
} | |
const $checkBox = $('#checkbox'); | |
const throttleWriteDom = _.throttle(writeDOM, 1000); | |
$("#container-result").click(e => { | |
if ($checkBox.is(':checked')) { | |
throttleWriteDom(e); | |
} else { | |
writeDOM(e); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment