Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 51
    Felix, I've read to this answer before but never replied. I grow concerned that people use self and that to refer to this. I feel this way because this is an overloaded variable used in different contexts; whereas self usually corresponds to the local instance and that usually refers to another object. I know you did not set this rule, as I've seen it appear in a number of other places, but it is also why I've started to use _this, but am not sure how others feel, except for the non-uniform practice that has resulted.
    – vol7ron
    Commented Sep 12, 2014 at 15:39
  • @FelixKling, it allows you to be super lazy with code like $(...).on('click', $.proxy(obj, 'function')) and $(...).off('click', obj.function).
    – zzzzBov
    Commented Mar 19, 2015 at 15:51
  • 6
    @FelixKling It can be useful at times to rely on Function.prototype.call () and Function.prototype.apply (). Particularly with apply () I've gotten a lot of mileage. I am less inclined to use bind () perhaps only out of habit though I am aware ( but not certain ) that there may be slight overhead advantages to using bind over the other options.
    – Nolo
    Commented Nov 15, 2016 at 6:02
  • 3
    It's important to note that bind() will take a snapshot of the context where it's first encountered during interpretation... That is to say, when JavaScript gets to the bind() function for the first time, it will take the context for this at that point! This can become tricky to troubleshoot, as the standard implementation of bind() CANNOT be altered. Once a function has been bound to another object, it will remain bound to that object, and attempting to rebind it won't work.
    – Jack_Hu
    Commented Jun 7, 2022 at 12:34