Last active
August 29, 2015 14:03
-
-
Save 350d/99ae183c9fa569b69314 to your computer and use it in GitHub Desktop.
Javascript debounce
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.prototype.debounce = function(delay) { | |
var timeout, callback = this; | |
return function() { | |
clearTimeout(timeout); | |
timeout = setTimeout(callback, delay); | |
} | |
} |
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
window.addEventListener('resize',test.debounce(200)); | |
// OR | |
$(function(){ | |
$(window).resize(test.debounce(200)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment