Created
April 1, 2017 10:04
-
-
Save think2011/90ae9903b57d54040f6607f37a7c65f0 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
function debounce(method, context) { | |
clearTimeout(method.tId); | |
method.tId = setTimeout(function() { | |
method.call(context); | |
}, 1000); | |
} | |
var throttle = function (action, delay){ | |
var last = 0; | |
return function(){ | |
var curr = +new Date(); | |
if (curr - last > delay) | |
action.apply(this, arguments); | |
last = curr; | |
}; | |
}; | |
func () { | |
// ... | |
} | |
var fn = throttle(func, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment