Why not take Javascript event delegation to the extreme?

后端 未结 3 642
一生所求
一生所求 2020-11-27 19:31

By now most folks on this site are probably aware that:

$(\"#someTable TD.foo\").click(function(){
    $(e.target).doSomething();
});

is go

3条回答
  •  攒了一身酷
    2020-11-27 20:17

    If you were doing it in plain JavaScript, the impact of random clicks anywhere on the page triggering events is almost zero. However in jQuery the consequence could be much greater due to the amount of raw JS commands that it has to run to produce the same effect.

    Personally, I find that a little delegation is good, but too much of it will start causing more problems than it solves.

提交回复
热议问题