[removed] inline functions vs predefined functions

前端 未结 13 1858
心在旅途
心在旅途 2020-12-02 11:00

Can any body throw me some arguments for using inline functions against passing predefined function name to some handler.

I.e. which is better:

相关标签:
13条回答
  • 2020-12-02 12:03

    There are no technical reasons to prefer one version over the other. For me is usually depends on two things:

    1. I want to resuse the passed callback in another context. In this case I define the function standalone and pass the reference.
    2. The callback is larger than ~10 lines of code and the function expects additional arguments after the callback. In this case it is hard to reconstruct, which values are actually passed to the function.

    Example:

    setTimeout(function() { // I need to scroll to see the other arguments
    
      // many lines of code
    
    }, 0); // <- where does this '0' belong to?
    
    0 讨论(0)
提交回复
热议问题