4 ms·
What I really like about the old style bind/live/delegate is that it's so grep-able. The new on()-based API makes it much harder to search through a codebase.
by jd 15y ago
What I really like about the old style bind/live/delegate is that it's so grep-able. The new on()-based API makes it much harder to search through a codebase.
In addition, when you see something like:
$('.table a').click(function() { ... } )
it immediately looks wrong, because there are probably multiple links in the table. Wrong code that looks wrong is great, because you can then refactor it as you come across it. But now you have to check if a second selector argument is passed to "on", to see if unnecessary event handlers are created.
- strickjb9 15y agoThis is also my biggest grip with the new .on(). I can't quickly look through code anymore since .on() can take on different meanings based on the arguments passed. When jQuery 1.7 was released I commented on this on the release notes page, I wasn't well received. It's refreshing to know that others feel the same way... http://blog.jquery.com/2011/11/03/jquery-1-7-released/#comment-527599 http://blog.jquery.com/2011/11/03/jquery-1-7-released/#comme...
- bdg 15y agoYou should take a look into event delegation with bubbling, event listeners should be minimal. http://javascript.info/tutorial/bubbling-and-capturing http://javascript.info/tutorial/bubbling-and-capturing http://javascript.info/tutorial/event-delegation http://javascript.info/tutorial/event-delegation