[英]Can someone explain me the flow of functions in this example?
I looked at the above piece of code and tried my best to search for solutions and posted it here after giving it my all.我查看了上面的代码,并尽力寻找解决方案,并在全力以赴后将其发布在这里。 This is my current understanding of the code: debounce() is called when there is an input and onInput() is passed to it as a callback, and debounce function return another function, the function being returned takes an argument which is the function passed by the debounce() aka the onInput(), I am stuck @ func.apply(null, args);
This is my current understanding of the code: debounce() is called when there is an input and onInput() is passed to it as a callback, and debounce function return another function, the function being returned takes an argument which is the function passed通过 debounce() aka onInput(),我被卡住了 @ func.apply(null, args); 1.Isn't func and args the same thing????
1.func和args不是一回事吗??? Someone please explain step by step is possible..
有人请逐步解释是可能的..
This is an example of debounce.这是一个去抖动的例子。
I have explained debounce with example, please check out the link debounce我已经用例子解释了 debounce,请查看链接debounce
debouce
is only called once on the initial run, it creates and returns a new anonymous function - the actual event handler. debouce
仅在初始运行时调用一次,它创建并返回一个新的匿名 function - 实际的事件处理程序。
When the input event is triggered, the previously created function is executed and will call func
(onInput) after 500ms.当输入事件被触发时,之前创建的function会被执行,并会在500ms后调用
func
(onInput)。 func
is only once passed to debounce, but args
are the actual input event arguments, which will be passed on to func
via apply . func
只传递给 debounce 一次,但args
是实际的输入事件 arguments,它将通过apply传递给func
。 In this case, apply is basically the same as func(...args);
在这种情况下,apply 与
func(...args);
基本相同。 So func
(aka onInput) will be called with the actual arguments from the input event after 500ms.因此
func
(又名 onInput)将在 500 毫秒后使用来自输入事件的实际 arguments 调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.