Understanding "this" keyword
- by Raffaele
In this commit there is a change I cannot explain
deferred.done.apply( deferred, arguments ).fail.apply( deferred, arguments );
becomes
deferred.done( arguments ).fail( arguments );
AFAIK, when you invoke a function as a member of some object like obj.func(), inside the function this is bound to obj, so there would be no use invoking a function through apply() just to bound this to obj. Instead, according to the comments, this was required because of some preceding $.Callbacks.add implementation.
My doubt is not about jQuery, but about the Javascript language itself: when you invoke a function like obj.func(), how can it be that inside func() the this keyword is not bound to obj?