Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> The method attaches the same event handler to every matched element in the selection.

Why is that a con for .bind()? This used to be considered a performance benefit compared to onclick.



I think you misread this. It does not bind the same instance of the handler to each element. Each element gets its own copy of this handler, hence the waste of memory.


What? No they don't, unless you're making the handler in a loop.

$( "div" ).click( function() {} );

Each div will have the same handler applied, it doesn't make a new one for every div.


You're confusing the callback with the actual event listener.


Compared to onclick, it's certainly a performance benefit.

However the difference here is in looping over every matched element to add the handler (bind) versus adding the handler to a single element further up the DOM tree (delegate).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: