Javascript higher-order functions -after

Posted May 25, 20201 min read

After the function
//after means to execute a method after executing a certain number of times, for example, the following function executes the fn function after count times

    function after(count, fn) {
        return() => {
            //Here we talk about count-- and --count, which is a good explanation. The minus sign will immediately perform a minus one operation in the front, and will be executed next time.
            if(-count === 0) {
    function callBack() {
        console.log("Execution result after two times")

    let countAfter = after(2, callBack)

    countAfter() //Execution result after two executions

//* Implementation analysis The principle of closure is used to store the count number. Every time the execution is done, the subtraction is performed. * The conditional execution function is completed.