The problem of Anonymous function in the throttling of vue function

question
this is the original function throttling method: anonymous function

(Note: return function () {} cannot be executed in methods )

excuse me, how can I change it to vue version?

as it is very commonly used in scrolling and Chinese search boxes, please consult

paste code:

created(){
    window.addEventListener("scroll", () => {
        this.debounce()(this._log, 1000);
    }
},
methods: {
    debounce (fn, idle) {
      let setTm;
      console.log("debounce")
      if (!idle || idle <= 0) return fn;
      return function () {
        clearTimeout(setTm);
        setTm = setTimeout(fn.bind(this, ...arguments), idle);
      }
    },
    _log(){
        console.log("_log")
    },
    
}

the way to bind should be:

var throttle = (fun, wait = 5000) => {
    var last = 0;
    return function () {
        var args = arguments;
        var ctx = this;
        var now = Date.now();
        if (now - last >= wait) {
            last = now;
            return fun.apply(ctx, args);
        }
        console.log(``)
    }
}

export default {
    name: 'VueComponent',
    methods: {
        scroll: throttle(function () {
            //...
        })
    }
}
Menu