Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
防抖和节流
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