Drink wine gently, feel life

Colloquially:

There’s a flock of ducks downstream from the bridge in front of the gate. Count them. (Start)

What is throttling?

It’s like counting ducks to the end and ignoring anyone who comes (🦆 is the most important).

Can not give up halfway, started can not block, do not hit the south wall do not turn back/a road to run to the black.

| ———————————— | ———————————— | ————————————

What is anti – shake?

Change a place you still count duck, began to count a part at any time to a brother a call you interrupted your train of thought, your heart silently read a ****, start again, and come to a person to ask the way, and plan your train of thought, also of start again, finally arrive at noon no one came, count a period of time duck count finished. (In the end, we still missed one haha, this is a sad story, just a joke to relieve the fatigue of study haha).

| | | — – | — — — — — – | | — — — — — —

Legend:

|

Click on the event,

— — —

Execute event time procedure.

Throttling code

In the end what matters is if judgment

// This code can only be entered once in a certain period of time. If the function cannot be executed, it will not be executed.

function throttleFn(fn,stime){
     let time = null;
     
     return fu(){
                 let args = argument;
                 if(! time){ time =setTimeout(() = >{
                        fn.apply(this,args);
                        //time indicates that the timer has a value.
                        time= null
                     },stime)
                }
            }
}
Copy the code

Anti – shake code

Ultimately what matters is clearTimeout()

function debounceFn(fn,stime){
    let time = null;
    retunr fu(){
        // The important point of anti-shake is here to be able to empty the timer at any time, do not let it dry
        clearTimeout(time);
        let args = argument;
        time = setTimeout(() = >{
            fn.apply(this,args);
         },stime)
    
    }

}

Copy the code

// There will be changes in the future