Skip to content

Instantly share code, notes, and snippets.

@think2011
Created April 1, 2017 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save think2011/90ae9903b57d54040f6607f37a7c65f0 to your computer and use it in GitHub Desktop.
Save think2011/90ae9903b57d54040f6607f37a7c65f0 to your computer and use it in GitHub Desktop.
防抖和节流
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