lodash debounce not working in anonymous function

阅读时长 3 分钟读完

Kristian Barrett提出了一个问题:lodash debounce not working in anonymous function,或许与您遇到的问题类似。

回答者Michael Dahl给出了该问题的处理方式:

As Palpatim explained, the reason lies in the fact that _.debouce(...) returns a function, which when invoked does it's magic.

Therefore in your #anonFunction example, you have a key listener, which when invoked does nothing but return a function to the invoker, which does nothing with the return values from the event listener.

This is a snippet of the _.debounce(...) definition:

-- -------------------- ---- -------
----------
-------- ------ ----- ---------- -
    --- --------
    ------ ---------- -
      --- ------- - ----- ---- - ----------
      --- ----- - ---------- -
        ------- - -----
        -- ------------ ------------------- ------
      --
      -- ---------- -- --------- ------------------- ------
      ----------------------
      ------- - ----------------- ------
    --
  - 

Your key event listener must invoke the returned function from _.debounce(...), or you can do as in your non-anonymous example and use the returned function from the _.debounce(...) call as your event listener.

希望本文对你有帮助,欢迎支持JavaScript中文网

来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/30520

纠错
反馈