最近再學習作圖片懶加載,其中要做滾動函數節流,看到這樣一段代碼// 簡單的節流函數//fun 要執行的函數//delay 延遲//time 在time時間內必須執行一次function throttle(fun, delay, time) { var timeout, startTime = new Date(); return function() { var context = this, args = arguments, curTime = new Date(); clearTimeout(timeout); // 如果達到了規定的觸發時間間隔,觸發 handler if (curTime - startTime >= time) { fun.apply(context, args); startTime = curTime; // 沒達到觸發間隔,重新設定定時器 } else { timeout = setTimeout(fun, delay); } };};// 實際想綁定在 scroll 事件上的 handlerfunction lazyload(event) {}// 采用了節流函數window.addEventListener('scroll',throttle(lazyload,500,1000));別的都能看懂,但是里面var content=this那里沒看懂,這里的this不是window嗎?后面fun.apply(content,args);豈不是把fun的this綁定為window;這樣有什么目的? 前端小白,求指導
關于節流函數
拉風的咖菲貓
2018-12-28 23:14:02