1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
function deb(fn,wait){ var timeout = null return function(){ if(timeout !== null) clearTimeout(timeout) timeout = setTimeout(fn,wait) } } function handel(){ console.log(Math.random()); } document.getElementById('btn').onclick= deb(handel,1000)
function handeler(){ console.log(Math.random()); } function thr(fn,delay){ let flag = true; return function(){ if(!flag){ return false } flag = false fn() setTimeout(()=>{ flag = true },delay) } } document.getElementById('btn').onclick= thr(handeler,3000)
|