Is there a difference between event.currentTarget
and this
? What about performance?
jQuery documentation clearly says, that event.currentTarget
is equal to this
in most cases (unless you changing scope manually with jQuery.proxy
or similar):
This property will typically be equal to the this of the function.
If you are using
jQuery.proxy
or another form of scope manipulation,this
will be equal to whatever context you have provided, notevent.currentTarget
https://api.jquery.com/event.currentTarget/
The currentTarget
event attribute returns the element whose event listeners triggered the event. This is only particularly useful during capturing and bubbling.
You can also use this
keyword, but when you use the Microsoft event registration model the this
keyword doesn’t refer to the HTML element.
Please see following link for more information: http://www.quirksmode.org/js/events_order.html
Problems of the Microsoft model
But when you use the Microsoft event registration model the this keyword doesn’t refer to the HTML element. Combined with the lack of a currentTarget–like property in the Microsoft model, this means that if you do
element1.attachEvent('onclick',doSomething)
element2.attachEvent('onclick',doSomething)
you cannot know which HTML element currently handles the event. This is the most serious problem with the Microsoft event registration model and for me it’s reason enough never to use it, not even in IE/Win only applications.
Note:: it may be,now resolved it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With