search

Home  >  Q&A  >  body text

js performance issues

There is a question that I have been holding back for a long time:
If you do not use event delegation, many people write like this (as shown above), looping the click event.
My question is:
Writing it this way is less code than writing it three times just for the page?
Or is the performance better? The good thing?

phpcn_u1582phpcn_u15822780 days ago483

reply all(4)I'll reply

  • 大家讲道理

    大家讲道理2017-05-19 10:26:14

    The code is less, more elegant, and there is not much difference in performance. But when writing like this, you have to be careful about the closure problem, that is, when the function uses i, you know.

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-19 10:26:14

    It’s just less code
    The performance is the same

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-19 10:26:14

    The logic is simple and less error-prone, which increases overhead, but is generally not enough to affect performance. If the handler is taken out separately, the impact will be smaller.

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-19 10:26:14

    The operation is the same, there is a loop, but the code is reduced.

    reply
    0
  • Cancelreply