Skip to content

Instantly share code, notes, and snippets.

@ldmarz
Last active August 19, 2018 18:16
Show Gist options
  • Save ldmarz/18d66de7e99ed65704ffa0ceb7ae8671 to your computer and use it in GitHub Desktop.
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
// 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