News for hackers. Stuff that matters.
Re:What does ‘that = this’ in JavaScript mean? by krptos on Saturday April 08, 2017 @04:38PM (#14068886)
I prefer using `self` rather than `that`, for caching `this`.

Must be because I have a strong python background, but generally I find "self" makes more sense than a wild "that"!

Re:What does ‘that = this’ in JavaScript mean? by pavlov on Saturday April 08, 2017 @05:28PM (#14069134)
I prefer to use a variable name that describes the type of the object in short.

So if my "this" object is actually an AwesomeTableWidget instance, I might do:

  var table = this;
I like the bit of extra documentation it provides... Or maybe this is just a remnant of all the C code I've written over the years, where it's common to have an object pointer as the first argument to a function and it's usually named like this.
Re:What does ‘that = this’ in JavaScript mean? by lorenzosnap on Saturday April 08, 2017 @06:07PM (#14069318)
you are so much better off if you can avoid using this when writing js. It's as bad as (and as useless) the keyword 'new'
Re:What does ‘that = this’ in JavaScript mean? by lorenzosnap on Sunday April 09, 2017 @11:30AM (#14072732)
negative votes here are totally unfair. I was pointing it out that the 'this' keyword is dangerous.
Re:What does ‘that = this’ in JavaScript mean? by timebomb on Monday April 10, 2017 @02:36PM (#14081281)
Why is it dangerous?
Re:What does ‘that = this’ in JavaScript mean? by karol on Saturday April 08, 2017 @05:10PM (#14069058)
By using `self` you shadow a global variable which is a reference to the current context (window object) in which the code is executed.
Re:What does ‘that = this’ in JavaScript mean? by lexicality on Saturday April 08, 2017 @06:20PM (#14069380)
Which should be accessed by window.self anyway so it doesn't really matter? There are so many poorly named global variables (top etc) that worrying about shadowing them seems meaningless.
Re:What does ‘that = this’ in JavaScript mean? by amorgaut on Monday April 10, 2017 @02:19AM (#14076451)
It matters when you are running in workers in which case the window object does not exists
Re:What does ‘that = this’ in JavaScript mean? by imdsm on Saturday April 08, 2017 @05:24PM (#14069114)
I always found context, i.e. let context = this, to be far more descriptive.
Re:What does ‘that = this’ in JavaScript mean? by vatotemking on Sunday April 09, 2017 @10:21PM (#14075556)
I use me. or if its a jquery object its $me. Probably because of my VB6 background. :-)