Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
arekxv10548yQuite standard practice to use that. Especially when you need contents from this inside a function. I prefer self as a name though. :)
-
carlos4188yThat 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.
-
@carlos so, why would u reference it as that? If writing $(this) is troublesome, u could do this = $(this) or $this = $(this) ..
-
carlos4188y@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 -
nmunro31908yFat arrow functions in ES2016/ES6/ES-whatever-we-call-it-now negate many of the instances I would typically use the "that = this" idiom.
-
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 -
Common inside loops.
$("ul").each (function() {
var that = $(this);
that.find("li").each (function () {
that.somethingWith (this);
});
});
Related Rants
-
linuxxx32*client calls in* Me: good morning, how can I help you? Client: my ip is blocked, could you unblock it for m...
-
DRSDavidSoft28Found this in our codebase, apparently one of my co-workers had written this
-
linuxxx23*client calls* "hello, we forgot the password to our WiFi router. Could you reset that for us?" 😐😶😮...
Oh wow.. you don't say!
undefined
variablenames
thisisthenewthat
wtf