48
Comments
  • 7
    Quite standard practice to use that. Especially when you need contents from this inside a function. I prefer self as a name though. :)
  • 1
    @arekxv .. i have seen that before. But not with this.. that cannot be this :P
  • 1
    That is actually quite interesting! I use `self` to reference to `this` but using `that` to reference to it as jQuery object sounds like a nice little idea.
  • 0
    @carlos so, why would u reference it as that? If writing $(this) is troublesome, u could do this = $(this) or $this = $(this) ..
  • 1
    @mohamedghr you sometimes wanna store the DOM object as itself but use the functions available to you by jQuery separately.

    But yes $this is also quite nice, I just like the naming concept lol
  • 1
    @carlos i get what u mean ;)
  • 1
  • 1
    I prefer to name it me
  • 0
  • 3
    I have superpowers: me.hide()
  • 1
    @Scrumplex .... ooooookay ;)
  • 1
    Fat arrow functions in ES2016/ES6/ES-whatever-we-call-it-now negate many of the instances I would typically use the "that = this" idiom.
  • 3
    Until fat arrows come to the rescue I would use

    $that = $(this)

    rather than

    that = $(this)

    so that I would know from reading later on that it is a JQuery element
  • 1
    I am surprized "this" and "self" are used instead of "me" and "I".
  • 0
    Common inside loops.

    $("ul").each (function() {
    var that = $(this);
    that.find("li").each (function () {
    that.somethingWith (this);
    });
    });
Add Comment