Debounce function with args underscore

后端 未结 4 1612
离开以前
离开以前 2021-01-31 06:51

I\'ve got a function which takes in some arguments. But usage of underscore debounce is :

var lazyLayout = _.debounce(calculateLayout, 300);

Bu

4条回答
  •  面向向阳花
    2021-01-31 07:43

    You don't need an anonymous function in the middle, arguments will automatically be passed to the original function when you run the debounced version.

      var debounceCalculate = _.debounce(calculateLayout, 300);
      debounceCalculate(a,b);
    

    As an advantage you don't have to hardcode-bind the arguments in advance

    You can try it and if curious just check the source

提交回复
热议问题