js函数防抖动

js事件轮询:https://blog.csdn.net/Metropolis_cn/article/details/79693685

js函数闭包:https://www.cnblogs.com/jhflyfish/p/11441195.html

js的apply用法:https://www.cnblogs.com/chenhuichao/p/8493095.html

js的setTimeout和clearTime:https://blog.csdn.net/ainuser/article/details/78882473

js函数防抖动:https://www.cnblogs.com/cc-freiheit/p/10827372.html

就是一开始设置一个timer为null,闭包函数里面执行setTimeout。

第一次,timer为null,把setTimeout赋值给timer。

后面每次先判断timer是否为null,不为null就用clearTime()清除掉timer,也就是不执行上一次setTimeout的回调函数。

因为是闭包函数,所有timer会保留下来。只会在规定时间内执行最后一次setTimout的回调函数。

你可能感兴趣的:(js)