使用args下划线的去抖动功能 [英] Debounce function with args underscore

查看:90
本文介绍了使用args下划线的去抖动功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个接受一些参数的函数。但是下划线去抖动的使用是:

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

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

但在我的情况下 calculateLayout 需要一些参数跑步。在这种情况下如何通过它们?

But in my case calculateLayout needs some arguments to run. How can I pass them in this case?

更新:

示例 calculateLayout function:

Sample calculateLayout function :

var calculateLayout = function(a,b) {
  console.log('a is ' + a + ' and b is ' + b);
}


推荐答案

你应该能够使用匿名函数作为第一个参数,然后调用你喜欢的任何内容:

You should be able to just use an anonymous function as the first argument, then call whatever you like in it:

_.debounce(function(){
    calculateLayout(20, 30);
}, 300);

这篇关于使用args下划线的去抖动功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆