Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delegate() vs on() in jquery?

Tags:

jquery

I know the difference between delegate() and on(), but I have a doubt that on() is very popular and faster than delegate() then why jquery is not removing the delegate() from its library.

live() has drawbacks then it is removed from jQuery-1.9 version. Also if we see the performance between on() and delegate() then on() is much faster than delegate().

Then any reason to keep delegate() in jQuery?

like image 858
Rohan Kumar Avatar asked Dec 14 '22 23:12

Rohan Kumar


1 Answers

This is what a member of the jQuery team wrote in regard to this issue in 2013:

"We haven't deprecated .bind or .delegate, nor have we indicated we're removing them at any point.

They're each only one line in the source so size reduction isn't much of a reason to remove them.

We deprecated .live because it has lots of confusing issues that we can't fix."

Basically, while delegate() has been superseded by on(), there are no future plans to deprecate delegate() due to the fact it takes up very little space (and doesn't cause any problems).

like image 160
dsgriffin Avatar answered Jan 14 '23 07:01

dsgriffin