簡體   English   中英

有人可以解釋一下這個例子中的功能流程嗎?

[英]Can someone explain me the flow of functions in this example?

多個回調

我查看了上面的代碼,並盡力尋找解決方案,並在全力以赴后將其發布在這里。 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.func和args不是一回事嗎??? 有人請逐步解釋是可能的..

這是一個去抖動的例子。

  • 去抖動是一種用於提高瀏覽器性能的做法。
  • 一種編程實踐,可確保耗時的任務不會如此頻繁地觸發。
  • 它用於限制調用 function 的速率。

我已經用例子解釋了 debounce,請查看鏈接debounce

debouce僅在初始運行時調用一次,它創建並返回一個新的匿名 function - 實際的事件處理程序。

當輸入事件被觸發時,之前創建的function會被執行,並會在500ms后調用func (onInput)。 func只傳遞給 debounce 一次,但args是實際的輸入事件 arguments,它將通過apply傳遞給func 在這種情況下,apply 與func(...args);基本相同。 因此func (又名 onInput)將在 500 毫秒后使用來自輸入事件的實際 arguments 調用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM