functiondebounce(fn,wait){vartimeout=null;returnfunction(){if(timeout!==null)clearTimeout(timeout)timeout=setTimeout(fn,wait)}}//處理函數(shù)functionhandle(){console.log(Math.random())}//滾動(dòng)事件window.addEventListener('scroll',debounce(handle,2000));第一個(gè)疑問debounce里面return后接的函數(shù)可以不帶函數(shù)名嗎?第二個(gè)疑問這個(gè)函數(shù)在這段代碼里面會(huì)執(zhí)行嗎,return只是返回了一個(gè)定時(shí)器函數(shù),可是還沒有調(diào)用它呢?原文鏈接https://zhuanlan.zhihu.com/p/...
求大佬指點(diǎn)哈!簡(jiǎn)單防抖代碼沒看懂?
溫溫醬
2019-08-09 23:30:19