Gintangible

Results 2 comments of Gintangible
trafficstars

防抖:n秒内函数只会执行一次,如果n秒内事件再次被触发,则重新计算时间 ``` function debounce(fn, time = 500){ let timer = null; return () => { clearTimeout(timer); timer = setTimeout(()=>{ fn.apply(this, arguments) },time) } } ``` 节流:事件在n秒内只会执行一次,在n秒内事件不再触发 ``` function throttle(fn, time){...

``` function transString(str){ return str.split('').map((item) =>{ return item == item.toLowerCase() ? item.toUpperCase() : item.toLowerCase(); }).join(''); } ```