Image stabilization

Image stabilizationlet time = null
function Fn(){
    if (time === null) {// Set the null assignment timer
            time = setTimeout(() = >{
               console.log('Lao Wang is very busy') // The body of code to execute
            },1000)}else { // If it is not null, empty the previous timer and set it to null, then call yourself again to reset the timer
            clearTimeout(this.time)
            this.time = null
            Fn()
    }
}

Copy the code

The throttle

The throttlelet time = null
/ / throttling
function fn(){
    if (time >= new Date().getTime()) return false // If the time after three seconds is longer than the current time, return false, exit the function (not executed)
    time = new Date().getTime() + 3000  / / three seconds
    return (() = > { // Call the function executed
        console.log('Lao Wang is very busy'()})})Copy the code