Understanding "this" keyword

Posted by Raffaele on Stack Overflow See other posts from Stack Overflow or by Raffaele
Published on 2012-06-25T08:48:07Z Indexed on 2012/06/25 9:16 UTC
Read the original article Hit count: 190

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery