Created
November 16, 2018 02:26
-
-
Save lichspace/15a0563dda3063c5d344ddf9ad2fcf2f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 去抖函数 | |
* @param func | |
* @param millisecond | |
*/ | |
module.exports = (func, millisecond)=>{ | |
//let timeId | |
let running = false | |
function debounced() { | |
if(running) return | |
running = true | |
setTimeout(()=>{ | |
func.apply(null,arguments) | |
running = false | |
},millisecond) | |
} | |
return debounced | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment