I stumbled upon this many times on the new code base that I was looking at and wondered if she had any correct reasoning?
You can use var that = this; to keep a reference to the current this object when later this will point to something else.
var that = this;
this
Example ( taken here ):
$('#element').click(function(){ // this is a reference to the element clicked on var that = this; $('.elements').each(function(){ // this is a reference to the current element in the loop // that is still a reference to the element clicked on }); });
Sometimes the value of this in JavaScript varies by region. this inside the constructor means something other than this inside the function. Here's a good article on this.
If you want to access "this" outside / inside the scope of a specific function call, where "this" can be changed. Just one example that I can think of.
Source: https://habr.com/ru/post/1483174/More articles:Is it possible to create any compile-time functions in Java? - javaExclude dynamic visualized user control from output caching - asp.netMysql multithreaded connection pool for Java applications - javaSetting autofocus attribute with broken javascript - javascriptwhy the missing optional parameter causes the "Incompatible types" error - genericsPylint in Sublime Text 2 - pluginsFind the number of digits in the fractional part of a decimal number in python - pythonDDD - CreatedBy / CreatedOn in a domain model? - design-patternsCreating an object of an abstract class URLConnection or HttpURLConnection in Java - javaSpring component scan corrupted in osgi container - javaAll Articles