作为标题,我如何在同一个回调函数中运行实时功能和反跳功能,例如
input.addEventListener('keyup', function () {
realtimeFn()
_.debounce(debounceFn, 1000) // how to code here...
})
function realtimeFn () { console.log(1) }
function debounceFn () { console.log(2) }
我想每次登录
1
,并在所有键盘输入和1秒之后登录2
。 最佳答案
Debounce返回一个去抖动的函数,您应该使用该返回的函数而不是调用debounce。此代码示例应做的事情。
var debounced = _.debounce(debounceFn, 1000) ;
input.addEventListener('keyup', function () {
realtimeFn();
debounced();
})
function realtimeFn () { console.log(1) }
function debounceFn () { console.log(2) }