function debounce(callback,time){ let t; return function(){ clearTimeout(t); t = setTimeout(callback,time); } } function foo(){ console.log("调用了一次"); } window.onclick = debounce(foo, 2000);