【发布时间】:2019-04-10 19:15:38
【问题描述】:
function A {
*// Inside function A We have below lines of code to do debouncing*
const debounce = (func, delay) => {
let debounceTimer
return function() {
const context = this
const args = arguments
clearTimeout(debounceTimer)
debounceTimer
= setTimeout(() => func.apply(context, args), delay)
}
}
button.addEventListener('click', debounce(function() {
*// Some Code Will be Ecexuted here after 3000 ms*
}, 3000));
*// function A ends here*
}
现在我想调用“clearTimeout(debounceTimer)”或任何其他可能的代码来清除另一个函数(函数 B)中去抖动的时间
function B {
*// How To Call "clearTimeout(debounceTimer)"???*
}
【问题讨论】:
-
*//an Unknown Syntax to do "clearTimeout(debounceTimer)"*应该是您要找的吗? -
是的...我想知道如何在这里调用 clearTimeout(debounceTimer)...
-
您的代码有点混乱,语义上函数A和B需要后跟括号...但是不清楚您要完成什么。让我明白如果我点击按钮会发生什么?
-
RxJS 非常擅长处理资源,无论调用/定义上下文如何
-
你为什么要使用
const context = this?const值是块范围的
标签: javascript function call debouncing