标签:
http://www.alloyteam.com/2012/11/javascript-throttle/
1. 必须用context传递this,否则setTimeout中this为window对象
function fn(){} var throttle=function(fn,delay) { var timer=null; return function() { var context=this,args=arguments; clearTimeout(timer); timer=setTimeout(function() { fn.apply(context,args); console.log(context);//input console.log(this);//window },delay); }; }; var btn=document.getElementById(‘my-btn‘); btn.addEventListener(‘click‘,throttle(fn,50),false);
标签:
原文地址:http://www.cnblogs.com/webfuryroad/p/4703283.html